Page 1 of 1

calculate date differenec

PostPosted: Mon Oct 26, 2015 4:03 pm
by gauravfrankly
Hi All,

I need to select all records from a table where date of insertion is less then 6 years from today.
we have a column in table having insertion time stamp.
currently I am using following query :
SELECT count(*) FROM TABLE1 WHERE APPLICATION_ID IN
(SELECT application_id FROM TABLE2
WHERE days(current timestamp)-days(LAST_UPDATE_DTTM) >= 'no of days in 6 years');
I am facing issue with number of days value. Because we may get 1 leap year in 6 year span and we may get 2 leap years.

Thank!!in advance. please help

Re: calculate date differenec

PostPosted: Mon Oct 26, 2015 5:28 pm
by Akatsukami
Do a one time calculation:
OLD  = CURRENT DATE - 6 YEARS;
DIFF = DAYS(CURRENT DATE - OLD);