Monday, May 29, 2006

DB2's Dates questions and answers



Q. What's DB2?



A: DB2' product is a relational database management system.



Q: Is there a way in DB2 date arithmetic to express the duration resulting from date subtraction, as a total-number-of-days (exact total, and not an approximate total)? To illustrate, the query:

SELECT DATE ('03/01/2004') - '12/01/2003'
returns a duration of 00000300 (i.e. 3-months). And those 3-months encompass a 29-day February plus a 31-day January plus a 31-day December (total 91 days). So I would be looking for a query which would return the number 91. Any ideas?



A: The answer lies in using the DAYS function. The following should return what you need:


SELECT DAYS('03/01/2004') - DAYS('12/01/2003')

This query will return to you the exact number of days between the two dates.




Please click here for more

No comments: