Difference between dates less than 1s

User avatar
ErikJan
BronzeLounger
Posts: 1306
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Difference between dates less than 1s

Post by ErikJan »

Sorry for the simple question but my brain seems to have stopped working... :grin:

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.

User avatar
HansV
Administrator
Posts: 79287
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Difference between dates less than 1s

Post by HansV »

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

User avatar
ErikJan
BronzeLounger
Posts: 1306
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Difference between dates less than 1s

Post by ErikJan »

Yeah... logical... sorry. Thanks Hans!