calculate date differenec



IBM's flagship relational database management system

calculate date differenec

Postby gauravfrankly » Mon Oct 26, 2015 4:03 pm

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
gauravfrankly
 
Posts: 39
Joined: Fri Aug 07, 2015 3:30 pm
Has thanked: 0 time
Been thanked: 0 time

Re: calculate date differenec

Postby Akatsukami » Mon Oct 26, 2015 5:28 pm

Do a one time calculation:
OLD  = CURRENT DATE - 6 YEARS;
DIFF = DAYS(CURRENT DATE - OLD);
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post