Reputation: 137
I am trying to condition a time read as a string lies between a specified time interval using VBScript. Following is the script:
dim splitString, currentTime
splitString = Split("12 59 00")
currentTime = TimeSerial(splitString(0),splitString(1), splitString(2))
If ((DateAdd("n",-1,time())) <= currentTime < DateAdd("n", 1,time())) Then
Wscript.Echo currentTime
End If
This does not seem to work. Getting an echo even if the current time is outside the time interval.
Upvotes: 1
Views: 676
Reputation: 137
I used DateDiff
. Modified the IF statement to:
If (DateDiff("n",DateAdd("n",-1,time()),currentTime) = 1 AND DateDiff("n",currentTime,DateAdd("n",1,time())) = 1) Then
Wscript.Echo currentTime
End If
Worked as expected.
Upvotes: 2
Reputation:
You need to evaluate both conditions independently.
dim splitString, currentTime
splitString = Split("3 39 00")
currentTime = TimeSerial(splitString(0),splitString(1), splitString(2))
If (DateAdd("n",-1,time()) <= currentTime) And (currentTime < DateAdd("n", 1,time())) Then
Wscript.Echo currentTime
End If
Upvotes: 2
Reputation: 38745
In Python you can check 'is in an interval' using the short
if x <= y < z:
...
but in VBScript you need the longer
If x <= y And y < z Then
...
Upvotes: 2