开发者

How can I compare two dates in vbscript/ASP?

开发者 https://www.devze.com 2022-12-21 06:56 出处:网络
Using ASP classic, I need to somehow compare two dates with each oth开发者_如何转开发er. How can I do this?Date1 = #rs["date"]#

Using ASP classic, I need to somehow compare two dates with each oth开发者_如何转开发er. How can I do this?


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


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().

0

精彩评论

暂无评论...
验证码 换一张
取 消