How does one handle rollovers when doing subtraction with time?
I find that when adding time, VBA handles rollovers at the 24-hour mark gracefully; but when i subtract hours, VBA gives me weird results;
Here is some code:
‘ subtract 12 hours, if resuting time is larger than current time then a 24-hour rollover occurred
‘ show current time and calculated time
If (TimeValue(TimeSerial(Hour(Time) – 12, Minute(Time), Second(Time)))) > TimeValue(Time()) Then
MsgBox “rollover”
MsgBox TimeValue(Time()) & ” ” & TimeValue(TimeSerial(Hour(Time) – 23, Minute(Time), Second(Time)))
End If
If the current time is 10:20:00 AM, I might get something like 12:28:04 PM (which is totally wrong);
how should i do time subtraction properly to handle the 24-hour rollover?
Thank you!
–llyal