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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing 2 dates

Status
Not open for further replies.

SonJ

Programmer
Oct 24, 2002
166
GB
Hi,

I am using ASP and SQL Server 2000.

I need to compare 2 dates that are beeing pulled from the database. In the database, they are of datatype datetime.

Currently, I am using the syntax of:

if date1 <> date2 then
some interesting stuff here
end if

but this seems to be very temperamental.

If anyone has any other ideas of how I can make this work, it would be much appreciated!

Thanks in advance.
 
If you are sure they are always dates the you can just use this:

if cDate(date1) <> cDate(date2) then


cDate will throw an error if you don't give it dates to work with.

You may also have a problem if the dates are not the same to the second. If you want to make sure that they are the same to the day then you should try this:

IF dateDiff(&quot;d&quot;,cDate(date1),cDate(date2)) > 0 THEN
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top