How to parse the year from a date.
Hi,
I have the following date format in database.
05-SEP-07
18-OCT-07
18-OCT-07
25-JUL-07
18-OCT-07
What I am trying to do is get only the full year from the date, example
2007
2008
2009
I tried to use extract function but that doesn't work due to ORA-01843: not a valid month.
Thanks in advance.
select extract(year from date '18-OCT-07') from dual;
OK. You got an error using date literal. Did you at least look in documentation on date literals? I guess not, otherwise you'd see that data literal synatx is DATE 'YYYY-MM-DD':
SQL> select extract(year from date '18-OCT-07') from dual;
select extract(year from date '18-OCT-07') from dual
ERROR at line 1:
ORA-01843: not a valid month
SQL>
SQL> select extract(year from date '2007-10-18') from dual;
EXTRACT(YEARFROMDATE'2007-10-18')
2007
SQL> SY.
P.S. "I have the following date format in database" is completely wrong dates are always stored in one format - internal date format that stores year, month, day, hour, minute and second. When you select date using client tools like SQL*Plus, SQL Developer, Toad, etc. date is converted to string using either explicit or implicit format where you specify which parts of date you want to see.
Similar Messages
-
How do I pull just the year from a date?
I'm trying to pull just the year from a date and cannot figure out how this can be done. I tried the SUBSTR fuction but its not acting how I would expect. What I'm wanting to do is write a condition that says Item Birth Year = Current Year minus 23 I have a calc that figures the age from the difference in the birthdate and current year but I'd really like to just write a condition based just one years. Can this be done?
Hello
SUBSTR will only work on a string. To extract portions of a date you need to use the TO_CHAR command.
To get the year you would use this: TO_CHAR(the_date,'YYYY')
TO_CHAR takes 2 switches, the date to be manipulated and the portion to be extracted, with the portion in single quotes.
Once you get used to manipulating dates like this other common pieces are: DD - extracts the day of the month, MON extracts the 3 character code for the month.
Thus you can use this: TO_CHAR(sysdate,'DD-MON-YYYY') and it will convert the current date, June 7th 2012 to 07-JUN-2012
Hope this helps
Best wishes
Michael -
XSLT Mapping: how to calculate Week number of the year from given date
Hi,
I have input as date, i need to know the Week number from that date in XSLT Coding.
for Eg: if date is 29-12-2009 it should give 53rd week of the year.
All answers will be appreciated.
Regards,
MayankHi add this statement to your XSLT Mappping
<xsl:stylesheet version="1.0" xmlns:java="http://xml.apache.org/xslt/java" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="java">
and use <xsl:template name="GetDateInLocal" xmlns:cal="xalan://java.util.GregorianCalendar"> in XSLT Mapping , write your logic.
cheers,
Raj -
How to get the values from struct data type using java code..?
Hi ,
I am newer to java.
we are using oracle database.
How to get the data from struct data type using java code.
Thanks in Advance.
Regards,
kumarHi Rajeev,
To retrieve a FilterContainer you will need to traverse the report structure:
ReportStructure boReportStructure = boDocumentInstance.getStructure();
ReportContainer boReportContainer = (ReportContainer) boReportStructure.getReportElement(0);
FilterContainer boFilterContainer = null;
if (boReportContainer.hasFilter()) {
boFilterContainer = boReportContainer.getFilter();
} else {
boFilterContainer = boReportContainer.createFilter(LogicalOperator.AND);
Calling boDocumentInstance.getStructure() will retrieve the entire structure for the document.
Calling boReportStructure.getReportElement(0) will retrieve the structure for the first report of the document.
Hope this helps.
Regards,
Dan -
How to subtract n years from a date
Hi all,
I need to subtract n years from a given date..
for example
if date is 21.07.200<b>6</b>.. if i want to subtract 2 years (n years) i should get 21.07.200<b>4</b>hi,
FM.
CCM_GO_BACK_MONTHS
Example
Data : Lv_current_date type dats,
lv_new_date type dats,
lv_no_months type NUMC3.
Lv_current_date = sy-datum.
lv_no_months = 12 * 2.
CCM_GO_BACK_MONTHS
IMPORTING
CURRDATE = Lv_current_date
BACKMONTHS = lv_no_months
EXPORTING
NEWDATE = lv_new_date.
Reward Points & Mark Helpful Answers.
to reward points ;click radio button next to the post.
select radio button as per the answers. -
How to get the week number of year from a Date object?
Hi!
I would like to know the week number of the year from a specified Date.
I dont know how to set the first day of week, and set the minimum days of a week.
I want to use Monday for first day of week, and at least 4 days of month in a week.
For example if its 1st, January is Friday, then the first week starts on 4th, Monday.
Anyone can help?Sorry. I should think before I move.
public static int getWeekOfYear(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setMinimalDaysInFirstWeek(4);
return calendar.get(Calendar.WEEK_OF_YEAR);
} -
How to change the year in a range of column dates to the new year?
How to change the year in a range of column dates to the new year?
Depends on the pattern of the dates. The last procedure will work for any pattern, or no pattern at all.
For examples.the dates are assumed to be in column A, starting at A2
Sequential dates?
Enter first updated date in the first cell.
Enter =A2+1 in cell A3. Copy the cell.
Select A3 to the end of the list. Paste.
With the cells still selected, Copy, then go Edit > Paste Values.
Evenly spaced dates?
Same procedure as above, but replace +1 in the formula with + and the number of days between dates in the list.
Randomly spaced dates?
Select cell B2. Press option-left arrow to insert a (temporary) column to the left of column B.
Click on the empty cell B2 in the new column. Enter the formula below:
=DATE(YEAR(A)+1,MONTH(A),DAY(A))
Copy the cell, then select B2 - Bn where n is the last ow containing a date to be converted. Paste,
With the cells still selected, Copy.
Click on A2, then go Edit > Paste values.
Click on the column B reference tab to select all of column B.
Hover the mouse over the right end of the reference tab, and click the black triangle when it appears.
Choose Delete Column from the menu that appears.
Regards,
Barry -
I-photo: I used 2 cameras to take pictures on a trip --- i have put the pictures from both cameras into an album --- when i click on view and then sort by date, the pictures do not sort by date --- any ideas on how to get the pics sorted by date?
Select all the photos that you need to change, then click the "Photos" menu and choose "Adjust Date and Time".
If you add a year, it will adjust all the photos that you selected by adding a year (so if you accidentally select one of the photos that already has "2012", that will change to "2013"). -
How to get the difference of two dates in years,months and days
Hi friends,
how to get the difference of two dates in years,months and days
for ex 2 years 3 months 13 days
select (sysdate-date_Start) from per_periods_of_service
thanksSomething like this...
SQL> ed
Wrote file afiedt.buf
1 with t as (select to_date('17-nov-2006','dd-mon-yyyy') as c_start_date, to_date('21-jan-2008','dd-mon-yyyy') as c_end_date from dual union all
2 select to_date('21-nov-2006','dd-mon-yyyy'), to_date('17-feb-2008','dd-mon-yyyy') from dual union all
3 select to_date('21-jun-2006','dd-mon-yyyy'), to_date('17-jul-2008','dd-mon-yyyy') from dual
4 )
5 -- end of test data
6 select c_start_date, c_end_date
7 ,trunc(months_between(c_end_date, c_start_date) / 12) as yrs
8 ,trunc(mod(months_between(c_end_date, c_start_date), 12)) as mnths
9 ,trunc(c_end_date - add_months(c_start_date, trunc(months_between(c_end_date, c_start_date)))) as dys
10* from t
SQL> /
C_START_D C_END_DAT YRS MNTHS DYS
17-NOV-06 21-JAN-08 1 2 4
21-NOV-06 17-FEB-08 1 2 27
21-JUN-06 17-JUL-08 2 0 26
SQL>But, don't forget that different months have different numbers of days, and leap years can effect it too. -
How to find the table in which data from a structure sits
Hi,
I want to know how to find the exact table where data sitting in various structures during runtime are stored.
For instance,in ME23N we have various tabs and data in those are held in various structures. This we can see by checking the technical setting of each field.
I want to know in which table the data is actually stored for each field and how to find them.
Any other means other than using "WHERE USED" option?
Thanks
CMAfter checking for technical field from the screen, when you reach out to structure, you can dbl click on the particular field's data element. From this data-element you can get to know in which tables it is used. Also if the data element refers to some master data field then you can check out its domain and in the domain you can refer the<b> value table</b> for that domain. This is what i will do if i am not sure about anything.
Hope it will help a little.
Jignesh. -
I loaded my ipad photos from camera and all the pictures sorted by date. I later sync my ipad with my computer and the photos were all reorganized into IMPRT folders an out of date sequence. Any idea how to put the photos back into date files other than reloading all of them from camera?
What version of iPhoto?
Select one and rotate it. Then rotate it back. Does that make it appear?
A much better work flow is the keep the photos after importing. Check the success the import, wait for at least one successful backup cycle then use you camera's format command to reformat the card
LN -
How to get name of the month from current date.
Hi,
How to get the name of the month from current date.
Thanks,
SenthilSethil,
Use your date(let us say Date1) instead of sy-datum.
CALL FUNCTION 'MONTH_NAMES_GET'
EXPORTING
LANGUAGE = SY-LANGU
IMPORTING
RETURN_CODE =
TABLES
MONTH_NAMES = itab_month
EXCEPTIONS
MONTH_NAMES_NOT_FOUND = 1
OTHERS = 2
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
READ TABLE itab_month
WITH KEY MNR = date1+4(2).
itab_month-LTX will contain the value you are looking for
Good luck
Raghava -
How to Find the Year to Date ?
Dear Experts
How to find the Year to date in BI 7.0 i.e(1st April of Current year to Tilldate) is there any Standard Variable is there ,Please let me know .as we are needed in our project.
Thanks in Advance
SatishHi,
I hope Stadard variables(Cumilated upto current fiscal year-0FYTCFP) will be avalable for this kind of requirement. Try to create a restricted key fig by make use of the standard variables...
This is just my assumption.
Message was edited by:
Kameswari Ponnuri -
How do i extract year from a variable???
Hi all,
I want to extract year from a parameter.
I tried the following, i'm getting errors.
When I executed the below code,
SELECT TO_CHAR(:X_PRM_YR_END_DT,'YYYY') FROM dual;
I got the following error.
ORA-01722:invalid number
When I executed the below code,
SELECT TO_DATE(:X_PRM_YR_END_DT,'YYYY') FROM dual;
SELECT to_char(TO_DATE(:X_PRM_YR_END_DT,'YYYY')) FROM dual;
I got the following error.
ORA-01830: date format end before converting entire input string
When I executed the below code,
SELECT extract(YEAR FROM :X_PRM_YR_END_DT) FROM dual;
SELECT extract(YEAR FROM 1/11/2013) FROM dual;
I got the following error.
ORA-30076: invalid extract field for extract source
How do i extract year from a variable???
Help me plz
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production.Try This,
select TO_CHAR(to_date('01/01/1980','dd/mm/yyyy'),'YYYY') FROM dual; -
How to get the today's julian date in java?
how to get the today's julian date in java?
hi can any one tell me how to get the todays julian date using Calender class or GregorianCalender class....
Julian date for 2006.November.01 AD 05:54 PM : 2454041.0
i have tryied with
calJ.setGregorianChange(new Date(Long.MAX_VALUE));
System.out.println(sdf2.format(calJ.getGregorianChange()));
thanks
Tushar
Message was edited by:
lad_tusharthanks a lot....for intrest....
I have found some details about the Julian calendar as follows:
The Julian date for 2006: JAN: 01:12:01:59 is 2453737.00138
245 represent the year digits for year 2006
3737 represent the date fir 1 Jan
.00138 represents the time for 12:01:59
Julian date change as per every day 12 noon it increase one digit in it.
As per ref from
http://www.aavso.org/observing/aids/jdcalendar.shtml
Also chk this calendar where Julian date is 20. October 2006 for 02 November 2006
As per ref from
http://www.calendar.sk/julian_calendar-en.php
I have tried the pure �GregorianCalendar� class from jdk1.4 API and its setGregorianChange method but not getting as per the expected Julian date format. Using the �setGregorianChange()� i have setting the cutover date to Long.MAX_VALUE it means GregorianCalendar now have to act as per the Julian calendar ...so after setting the cutover date it return me changed date using �getGregorianChange()� but that was not the Julian date of the current date...as expected or as per above both scenario. Even though the last two digits are nowhere equal to the actual Julian date.
Program
GregorianCalendar cal = new GregorianCalendar();
cal.setGregorianChange(new Date(Long.MAX_VALUE)); // setting the calendar to act as a pure Julian calendar.
// cal.set(Calendar.DATE, new Date().getDate()); // seting the current date
// Date todayJD = cal.getGregorianChange(); // getting the changed date after the setGregorianChange
Date todayJD = cal.getTime(); // getting the calculated time of today�s Julian date
SimpleDateFormat sdfJulianDate = new SimpleDateFormat("yyDDD");
SimpleDateFormat sdfJuliandayOfYear = new SimpleDateFormat("DDD");
System.out.println("today Date = " + new Date());
System.out.println("Today as julian date = " + sdfJulianDate.format(todayJD));
System.out.println("Today as day of year = " + sdfJuliandayOfYear.format(todayJD));
OUTPUT:
USING : Date todayJD = cal.getGregorianChange();
Today Date = Thu Nov 02 15:17:05 IST 2006
Today as julian date = 94229
Today as day of year = 229
USING : cal.set(Calendar.DATE, new Date().getDate());
Today Date = Thu Nov 02 15:19:22 IST 2006
Today as julian date = 06319
Today as day of year = 319
USING : Date todayJD = cal.getTime();
Today Date = Thu Nov 02 15:17:59 IST 2006
Today as julian date = 06306
Today as day of year = 306
There is one another concept i found to get the Julian day of the year as per the Julian day chart mention on nasa site (http://angler.larc.nasa.gov/armsgp/JulianDayChart.html) and i m getting the moth of the year that is 306 for nov 02 2006 using getTime() method in above code then the out put is right for Julian day. But it was not as per the expected Julian date format. So in conclusion we can only able to retrieve the day of year for the Julian calendar. hope their will be a solution for this problem in java api ....else we allways have to depend upon the third party api that was not accepteble some times.....
Kindly chk chart on the site
http://angler.larc.nasa.gov/armsgp/JulianDayChart.html
http://weather.uwaterloo.ca/julian.html
http://www.fs.fed.us/raws/book/julian.shtml
Thanks,
Tushar Lad
Maybe you are looking for
-
Help filling out PDF - How can I get text to fit in text boxes?
I need to fill out an application that is in the PDF format. When I filled it out, there were a few text boxes where the text did not wrap around. In other words, some of the text doesn't show. There is not enough space for what I typed. When I print
-
Duubt in File -XI-IDOC Scenario
hi In my Scenario FILE-XI-IDOC Everything is fine.But IDOC can't display in R/3 when i checked with we05. Please provide solution. Thanks
-
Update Telephone Extension of Customer Master
Hi all, I want to update Telephone Extension of the Customer through my program. Is there any function module which would update the Extension. the case is I am getting an inbound idoc which does not process the Extension as the extension segme
-
L440 noisy drive with CDs or DVDs
Hello Have just bought a L440. I am surprised how noisy the drive is when playing either CDs or DVDs. I have owned many laptops and desktops with built in drives and when they recognise a CD/DVD they spool down to barely audible to allow playback. Bu
-
i have downloaded a purchased photoshop elements 13 and can't get it working as my computer is 64-bit how do i change either my computer or the purchased product