Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Date Comparison in ASP...

Posted on 2004-11-08
4
Medium Priority
?
464 Views
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>")
                  response.end

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

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?

Thanks!
0
Comment
Question by:seahawk9
  • 2
4 Comments
 
LVL 10

Expert Comment

by:lengreen
ID: 12527727
Hi use

CDate(mydate)

cheers

Len
0
 
LVL 10

Accepted Solution

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

'.........

end if
0
 
LVL 46

Expert Comment

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

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

For details:

http://www.devguru.com/Technologies/vbscript/quickref/datediff.html

FtB
0
 

Author Comment

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

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