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.