Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I compare two dates in vbscript/ASP?

Using ASP classic, I need to somehow compare two dates with each other. How can I do this?

like image 553
poo Avatar asked Feb 24 '10 15:02

poo


People also ask

How do you compare two dates in a type script?

Call the getTime() method on each date to get a timestamp. Compare the timestamp of the dates. If a date's timestamp is greater than another's, then that date comes after.

How do I compare two date dates?

Use the datetime Module and the < / > Operator to Compare Two Dates in Python. datetime and simple comparison operators < or > can be used to compare two dates.

Which method is used to compare two date values?

For comparing the two dates, we have used the compareTo() method. If both dates are equal it prints Both dates are equal. If date1 is greater than date2, it prints Date 1 comes after Date 2.


2 Answers

If Date1 > Date2 Then
  ' Date1 occurred after Date 2
End If

Use >, < and = like comparing numbers (and >=, <= and <> too). Smaller dates are more historic.

This of course assumes that Date1 and Date2 are actually Date or DateTime objects. If they aren't, you'll need to convert them to Date objects first using CDate().

like image 38
Welbog Avatar answered Sep 18 '22 19:09

Welbog


Date1 = #rs["date"]#
Date2 = #12/1/2009#


If DateDiff("d", Date1, Date2) > 1 Then
    response.write "This date is before 12/1/2009"
Else
    response.write "This date is after 12/1/2009"
End If
like image 89
Mikos Avatar answered Sep 19 '22 19:09

Mikos