Question : Date Difference

This could be very simple, but i'm not getting it right..
    I have two dates..i have to make sure, their difference is always less than 6 months.
   How to write SQL for it? Please help.

My main problem is : When i do,

SELECT MONTH (DATE ('2005-03-01')) - MONTH (DATE ('2005-02-28')) FROM SYSIBM.SYSDUMMY1
 
it gives the answer as 1, but the difference is not really a month; it is just 1 day..

Answer : Date Difference

Hi pvs,

There are several ways to do this.

If you can live with an "almost", convert to days and compare to 180 or 182.

  SELECT days (date1) - days (date2) ....

Otherwise, you'll probably want to call TIMESTAMPDIFF

   SELECT TIMESTAMPDIFF (64,CHAR(TIMESTAMP('2001-09-29-11.25.42.483219') -
                TIMESTAMP('2001-09-26-12.07.58.065497')))
   FROM sysibm.sysdummy1;



Kent
Random Solutions  
 
programming4us programming4us