...

View Full Version : Help with Comparing Dates



Carl_FK
01-11-2005, 03:55 PM
Hi Everyone,

This is my first post, so wohey! :D

Anyway, to the point, I would like some help on comparing dates.
Basically, I have a date (dd/mm/yy) in my SQL database, which I can connect to, and output onto a page. I need to compare the date in my database, with todays date.
And, if todays date is after (or equal to) the date in the database, it outputs a string of text.

Sounds quite simple... although I'm not sure how to do this.
P.S. I'm quite experienced with ASP although never tried this. :)

Thanks,

Carl.

Bullschmidt
01-12-2005, 04:12 AM
Hi Carl!

If objRS("TheDateField") <= Date() Then
...
End If

glenngv
01-12-2005, 04:22 AM
DateDiff (http://www.devguru.com/Technologies/vbscript/quickref/datediff.html)

Carl_FK
01-12-2005, 12:16 PM
Thanks for the fast response guys!

I will try them out tonight and let you know how I got on. :)

Carl_FK
01-20-2005, 01:23 PM
Hi Guys

Bullschmidt, unfortunately yours didnt seem to do anything... There were no errors, but it didnt return a string :confused:

glenngv, i had a look at yours, but it doesnt seem like what I want (correct me if i'm wrong), but do you recon you could give an example.

Any other ideas?

Thanks guys

glenngv
01-20-2005, 02:19 PM
glenngv, i had a look at yours, but it doesnt seem like what I want (correct me if i'm wrong), but do you recon you could give an example.

The link that I posted already gives you examples.

<%=DateDiff("d", Date, "1/1/2000") %>

<% olddate = #6/26/43# %>
<% nowdate = Now %>
<% =DateDiff("S", nowdate, olddate) %>

Bullschmidt
01-20-2005, 06:15 PM
Hi Guys

Bullschmidt, unfortunately yours didnt seem to do anything... There were no errors, but it didnt return a string :confused:


Well the only other thing I can think of is to make sure that the field in question in the database table really is a date/time field.

fractalvibes
01-20-2005, 09:31 PM
In SQL:

select col1
,col2
etc.
(CASE WHEN DateField <= CURRENT DATE THEN
'Yep'
Else
'Nope'
End) AS DoPrint
from your table
where .....

in code:
If rs("DoPrint") = "yep" then
'go ahead and output your string of text
End if



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum