Skip to Content
Custom Search

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

It will help someone help

It will help someone help you if you show the bit of problem code and the diagnostic(s) generated.

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.

format of days difference filed

try it with S9(5) COMP

Click the +1 button  below to share it with your friends and colleagues

 

Share this if you liked it!

 

Disclaimer



Who's online

There are currently 0 users and 26 guests online.
Dr. Radut | page