Difference in number of days using DB2 days function
Difference in number of day using DB2 days function
DAYS - This returns the number of days starting from date '0001-01-01'.
SELECT DAYS('2010-10-31') FROM SYSIBM.SYSDUMMY1
This will query will return 734076.
If you wish to calculate difference in number of days between two dates then the following query can be used
SELECT DAYS('2010-10-31')-DAYS('1990-10-01') FROM SYSIBM.SYSDUMMY1
This will query will return 7335. Remember first date is the To date and the second date is from date
The other functions are Day, Month, Year
DAY - This returns the day from a date
SELECT DAY ('2010-10-31') FROM SYSIBM.SYSDUMMY1
This query will return 31.
Month - This returns the month from a date
SELECT MONTH('2010-10-31') FROM SYSIBM.SYSDUMMY1
This query will return 10.
Year - This returns the year from a date
SELECT YEAR('2010-10-31') FROM SYSIBM.SYSDUMMY1
This query will return 2010.
Comments
Anonymous
Thu, 10/25/2012 - 20:29
Permalink
format of days difference filed
what is the format in working storage of the field where 7335? I defined it as numeric pic 9(5) but can't compile it.
Anonymous
Mon, 05/13/2013 - 10:03
Permalink
format of days difference filed
try it with S9(5) COMP
DikDude
Mon, 10/29/2012 - 18:20
Permalink
It will help someone help
It will help someone help you if you show the bit of problem code and the diagnostic(s) generated.