PDA

View Full Version : comparing date


havey
06-09-2005, 11:18 PM
hi, i have pulled a date field out of the databse and would like to compare it to current Date.

But i would like to redirect the user is a year has passed from the db date to the current date. Both date fields are in the same format, how can i determine by comparison if a year has gone by?
cv = rs("originalDate")
cw = Date()

fractalvibes
06-10-2005, 12:00 AM
select
(case when yourdatefield <= (current date - 1 year) then
'a year or more'
else
'less than a year'
end) as mydatecomp

from some table
where....


fv

miranda
06-10-2005, 02:53 AM
testing for 365 days is shortest code to do this

If DateDiff("d",cv, Date()) >= 365 Then
Response.Redirect("somepage.asp")
End If

glenngv
06-10-2005, 04:47 AM
You can also use DateDiff for years.

DateDiff("YYYY",cv, Date())

fractalvibes
06-10-2005, 05:16 AM
Might be best to do your date checking in the SQL as I suggested. You can
quite a lot through SQL alone...and probably more efficiently.

fv

miranda
06-10-2005, 05:05 PM
yes you can do datediff for years but it only looks at the year. So if the value of cv is 12/31/2004 and today's date is 6/10/2005 using
DateDiff("yyyy", cv, Date()) will return 1 even though it hasn't been a year that has passed.