Tuesday, June 16, 2020

VBA Datediff Function Example



Sub VBADateDiff()
    ''datediff returns an integer value positive, negative or zero
    ''difference of days between dates
    Debug.Print VBA.DateDiff("d", "2/27/2019", "3/11/2021")
    ''difference of months between dates
    Debug.Print VBA.DateDiff("m", "2/27/2019", "3/11/2021")
    ''difference of weeks between dates
    Debug.Print VBA.DateDiff("w", "2/27/2019", "3/11/2021")
    
    ''difference of days between dates
    Debug.Print VBA.DateDiff("d", "2/27/2019", "2/28/2019")
    ''difference of months between dates
    Debug.Print VBA.DateDiff("m", "2/27/2019", "3/2/2019")
    ''difference of weeks between dates
    Debug.Print VBA.DateDiff("w", "2/27/2019", "3/2/2019")
    
    ''difference of days between dates
    Debug.Print VBA.DateDiff("d", "3/11/2021", "2/27/2019")
End Sub

OUTPUT---

'743
'25
'106
'1
'1
'0
'-743

No comments:

Post a Comment

Hot Topics