Sorry for the simple question but my brain seems to have stopped working...
I have two VBA Date-type variables and I want to know if the difference between the two is less than one second... How do I do that (Datediff doesn't seem to do that right away)?
I know I can first compare the dates and if they are the same then compare the times but that seems overly complex.
Difference between dates less than 1s
-
- BronzeLounger
- Posts: 1306
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
-
- Administrator
- Posts: 79287
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Difference between dates less than 1s
Let's say the variables are named d1 and d2.
Code: Select all
If d2 = d1 Then
MsgBox "Times are the same"
ElseIf Abs(d2 - d1) < TimeSerial(0, 0, 1) Then
MsgBox "Difference is less than 1 second"
Else
MsgBox "Difference is 1 second or more"
End If
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1306
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
Re: Difference between dates less than 1s
Yeah... logical... sorry. Thanks Hans!