2015-08-21 34 views
2

我試圖在now()超過開始日期和開始時間時纔會執行其他代碼。僅在特定日期和時間內運行條件

出於某種原因,它不是返回strresponse,而是在else之後執行代碼。

如果我刪除starttime,代碼工作正常,但我也需要它在一天的特定時間運行。

startdate= dateserial(2015, 08, 27) 
starttime =timevalue ("12:00:00 pm") 
IF date() < startdate and time() < starttime then 

strResponse ="Auction begins at " & startdate & " " &starttime & " please wait untill auction has started" 

else 

回答

0

VBScript的日期數據類型(技術上是Variant)存儲日期和時間,因此不需要兩個單獨的變量。

Dim dt 
dt = DateSerial(2015, 8, 27) + TimeSerial(12, 0, 0) 

然後,你可以使用Now()功能,以獲取比較當前日期和時間:

If Now() < dt Then 

    strResponse = "Auction begins at " & dt & "." 

Else 

    ' Time for auction 

End If 

說實話,雖然我看不出有任何理由爲什麼你原來的代碼不應該沒有工作。你的意思是中午而不是午夜,我假設。

相關問題