Time()的经典ASP Vbscript条件语句未给出正确的结果

Time()的经典ASP Vbscript条件语句未给出正确的结果,time,vbscript,asp-classic,conditional-statements,Time,Vbscript,Asp Classic,Conditional Statements,我正在vbscript中处理一个简单的条件语句,以检查一个时间是否早于另一个时间。它不起作用,也没有任何意义。仅仅使用日期似乎有效,但我需要使用时间。。。这是行不通的 dim startDateStartTime, CurrentDateCurrentTime startDateStartTime = FormatDateTime("12:00:00 PM") response.Write("The Course Star

我正在vbscript中处理一个简单的条件语句,以检查一个时间是否早于另一个时间。它不起作用,也没有任何意义。仅仅使用日期似乎有效,但我需要使用时间。。。这是行不通的

dim startDateStartTime, CurrentDateCurrentTime

                startDateStartTime = FormatDateTime("12:00:00 PM")
                    response.Write("The Course Starts at: ["&startDateStartTime&"]<br/>")

                CurrentDateCurrentTime = FormatDateTime("5:00:00 AM")
                    response.Write("The Current Time is: ["&CurrentDateCurrentTime&"]<br/>")


                if CurrentDateCurrentTime < startDateStartTime then

                    response.Write("The current time is less then the course start time. Keep Course open")

                else

                    response.Write("The current time is greater then the course start time. Close Course")

                end if
dim startDateStartTime,CurrentDateCurrentTime
startDateStartTime=FormatDateTime(“下午12:00:00”)
回答。写(“课程开始于:[”&startDateStartTime&“]
”) CurrentDateCurrentTime=FormatDateTime(“上午5:00:00”) Write(“当前时间为:[“&CurrentDateCurrentTime&“]
”) 如果CurrentDateCurrentTime
此语句的输出为:

课程开始时间:[12:00:00 PM]

当前时间为:[5:00:00 AM]

当前时间大于课程开始时间。结束课程

这显然是错误的,因为上午5点不到下午12点。我不明白?

FormatDateTime()返回一个字符串:

>> WScript.Echo TypeName(FormatDateTime("12:00:00 PM"))
>>
String
那么你的

if CurrentDateCurrentTime < startDateStartTime then
如果CurrentDateCurrentTime

将以“5”开头的字符串与以“1”开头的字符串进行比较。您需要比较(子类型的变量)日期。

要比较日期/时间,您应该使用函数DateDiff

DateDiff(interval, date1, date2, [firstdayofweek], [firstweekofyear])