Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Missing something obvious...

Status
Not open for further replies.

Serin

Technical User
Mar 11, 2002
5
0
0
US
It seems to me there's an easy way to calculate a date difference, in days, between two dates. I'm trying to write an algorithm to wipe out records over 90 days old, and I don't think I need 20 lines of code for something that simple. Can someone help me? Thanks!

Serin Some people ask, "Why get out of bed in the morning?" but I say, "Where's my beer?"
 
the function you want is DATEDIFF.

DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])

code would be:

Dim NumOfDays;
NumOfDays=DateDiff("d",ButTheDateFromRecordHere,Now())


Then do an if then comparasion to check if NumOfDays is greater than 90.
 
Simply daily date math is easy as cake:

If EndDate-StartDate > 90 then
'do your stuff here
else
'do some other stuff here
end If

No need for even the DateDiff function. DATEDIFF is really only needed if you want something OTHER than DAY differences - second, hour, minute, week, month, etc etc etc...

Ex-JimAtTheFAA
78.5% of all statistics are made up on the spot.
Another free Access forum:
 
Thanks I appreciate it... I knew it was something simple.

Serin Some people ask, "Why get out of bed in the morning?" but I say, "Where's my beer?"
 
DOH!!!!

Your right Wildhare. And the funny part is, I've used the same code in your example so many times that I should have known.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top