More DBA job interview questions and answers at
http://dba.fyicenter.com/Interview-Questions/
(Continued from previous question...)
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)?
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/2008') - '12/01/2007'
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/2008') - DAYS('12/01/2007')
This query will return to you the exact number of days between the two dates.
(Continued on next question...)