Date Comparison in ASP...

Posted on 2004-11-08
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
    LVL 10

    Expert Comment

    Hi use



    LVL 10

    Accepted Solution

    if CDate(strStDate) > Cdate(strEndDate) then


    end if
    LVL 46

    Expert Comment

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

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

    For details:


    Author Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
    I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now