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

Comparing Dates

Status
Not open for further replies.

emozley

Technical User
Jan 14, 2003
769
0
0
GB
Hi,

I have an array that has a series of dates in it. I am trying to loop through the array doing one thing if the date is before 31st March 2008 and another thing if it is after.

Unfortunately it's not working - if I do the following:

<%
Response.Write(FormatDateTime(02/05/2008)<FormatDateTime(31/03/2008))
%>

It comes back as True - ie it is saying 2nd May 2008 is before 31st March 2008 which it clearly shouldn't be.

I have tried it with and without FormatDateTime.

Is it possible to compare dates in this way or do I have to do it using DateDiff("d", x, y)?

Thanks very much

Ed
 
FormatDateTime converts the date to a string... you can compare strings but it will be an alphabetical comparison.

Alphabetically, April comes before January so it sounds like you need to use DateDiff.
 
Or... Convert them to the Date data type and compare them.

<%
Response.Write([!]cDate("[/!]02/05/2008[!]")[/!]<[!]cDate("[/!]31/03/2008[!]")[/!])
%>

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top