Months difference


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'**********************************************************************************************************
' Name:                 monthsDifference
' Author:               mielk | 2012-06-15
'
' Comment:              Function to count the difference in months between two dates.
'
' Parameters:
'   startDate           Start date.
'   endDate             End date.
'
' Returns:
'   Long                The number of months between two given dates.
'                       If both dates were in the same month, 0 is returned.
'                       If the given end date is later than the start date, negative value is returned.
'
'
' --- Changes log -----------------------------------------------------------------------------------------
' 2012-06-15       mielk       Function created.
'**********************************************************************************************************
Public Function monthsDifference(startDate As Date, endDate As Date) As Long
    Const METHOD_NAME As String = "monthsDifference"
    '------------------------------------------------------------------------------------------------------

    monthsDifference = VBA.DateDiff("m", startDate, endDate)

End Function