Page 1 of 1
DATE from day of the year
Posted:
Wed Apr 06, 2016 4:11 pm
by Papya013
Hi Team,
I am new to DB2, could you please help me how to get the DATE from day of the year.
Ex: If day of the year if 97 for 2016-04-06
97 will be my input and the expected date is 2016-04-06.
Re: DATE from day of the year
Posted:
Wed Apr 06, 2016 4:31 pm
by NicC
Have you looked into the DB2 manual to see if there is a function to do it? If there isn't then you will have to do it in a program. You really should use SQL for what it was designed for - storing and retrieving data not doing your program's work.
Re: DATE from day of the year
Posted:
Sun May 08, 2016 5:59 pm
by Raja190
Hey Papya013,
Can you try with below and let me know the result ?
select (TO_DATE(TO_CHAR(GLDGJ+1900000),'YYYYDDD')) as date from table.
here "GLDGJ " is the field name from table.
Re: DATE from day of the year
Posted:
Sun May 08, 2016 7:39 pm
by enrico-sorichetti
the day number as input is not enough,
You need also the year
the day number for march first of a NON leap Year will the same as the day number of february 29th of a leap year
Re: DATE from day of the year
Posted:
Mon May 09, 2016 12:15 am
by Akatsukami
If the SQL is embedded in another language, would it not be easier to invoke the LE CEEDAYS and CEEDATE functions?