pracuję nad prostą instrukcją warunkową wvbscript, aby sprawdzić, czy czas jest wcześniejszy niż inny czas. i nie działa ani nie ma sensu. tylko używanie dat wydaje się działać, ale muszę użyć czasu ... który nie działa.
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
Wynik dla tego oświadczenia to:
Kurs zaczyna się o: [12:00:00 PM]
Aktualny czas to: [5:00:00 AM]
Aktualny czas jest większy niż czas rozpoczęcia kursu. Zamknij kurs
co jest oczywiście błędne, ponieważ 5 rano trwa krócej niż 12 wieczorem. Nie rozumiem?
Odpowiedzi:
2 dla odpowiedzi № 1FormatDateTime () zwraca ciąg znaków:
>> WScript.Echo TypeName(FormatDateTime("12:00:00 PM"))
>>
String
Więc twój
if CurrentDateCurrentTime < startDateStartTime then
porównuje ciąg od "5" do łańcucha zaczynającego się od "1". Musisz porównać (zmienne podtypu) Data (y).
0 dla odpowiedzi nr 2
Aby porównać datę / godzinę, powinieneś użyć funkcji DateDiff
DateDiff(interval, date1, date2, [firstdayofweek], [firstweekofyear])