Date Subtraction

Database
Fan

Date Subtraction

Hi All,

Difference between 2 dates will give us in Days. As I am casting to Interval Month it should give us in MONTHS..
SELECT (DATE '2010-07-06' - DATE '2010-06-26' ) MONTH
Output is : 1

Note: But the difference between 2 dates is 10 days and it is less than a Month so it should return 0 .

Could anyone tell me how to achieve "SELECT (DATE '2010-07-06' - DATE '2010-06-26' ) MONTH = 0"?

Arvind.
2 REPLIES
Junior Supporter

Re: Date Subtraction

Something like this may help:

SELECT CAST((CAST('2010-07-06' AS INTEGER) - CAST('2010-06-26' AS INTEGER)) /100 AS INTERVAL MONTH) Diff_In_Months;

*** Query completed. One row found. One column returned.
*** Total elapsed time was 1 second.

Diff_In_Months
--------------
0

HTH.

Cheers.

Carlos.
Fan

Re: Date Subtraction

Thanks Carlos!!