Learn how to a build a cloud-first strategyRegister Now


Date Comparison in ASP...

Posted on 2004-11-08
Medium Priority
Last Modified: 2008-03-10

This is likely a simple problem, but I ran across an error in the code. This line of code:
if tempSchedule(intLoop,1) < strStDate then DateError = true end if
is coming up true, even though the the first date in the test is 5/3/2005 and the second date is 11/10/2004.
I put this debug code in:

if tempSchedule(intLoop,1) < strStDate then DateError = true end if
Response.Write("tempSchedule(intLoop,1) " & tempSchedule(intLoop,1) & "<BR>")
                  Response.Write("strStDate" & strStDate & "<BR>")

and get the following results:
tempSchedule(intLoop,1) 5/3/2005

So I am wondering if perhaps the fields are not formatting as dates? Or do I need to format them as dates in the test?             

I went through the code and I don't see where it was cast as a date, here is some of the code where it was definied.
strStDate = session("strStDate")
strStDate = mmxRS("START_DATE")
dim strStDate, strEndDate, strTempDate, intOpenEnd
strStDate = Request.Form("bDate")
strTempDate = strStDate

Anyway, how do you do a date comparison in ASP?

Question by:seahawk9
  • 2
LVL 10

Expert Comment

ID: 12527727
Hi use



LVL 10

Accepted Solution

lengreen earned 500 total points
ID: 12527745
if CDate(strStDate) > Cdate(strEndDate) then


end if
LVL 46

Expert Comment

ID: 12527746
I would try using the DateDiff() method to see:

if DateDiff("d",datDate1,datDate2)<0 then
   'do something
end if

For details:



Author Comment

ID: 12527781
That's it my friend! Thanks a bunch. DateDiff was a good suggestion as well, but CDate worked just fine.

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

804 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question