All Forums Database
arvind 4 posts Joined 05/09
07 Jul 2010
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.

CarlosAL 512 posts Joined 04/08
07 Jul 2010

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.

arvind 4 posts Joined 05/09
08 Jul 2010

Thanks Carlos!!

You must sign in to leave a comment.