Weeks 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
27
28
'**********************************************************************************************************
' Name:                 weeksDifference
' Author:               mielk | 2012-06-15
'
' Comment:              Function to count the difference in weeks between two dates.
'
' Parameters:
'   startDate           Start date.
'   endDate             End date.
'   firstDayOfWeek      Day assumed to be the first day of the week.
'
' Returns:
'   Long                The number of weeks between two given dates.
'                       If both dates were in the same week, 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 weeksDifference(startDate As Date, endDate As Date, _
                                             Optional firstDayOfWeek As VBA.VbDayOfWeek = vbMonday) As Long
    Const METHOD_NAME As String = "weeksDifference"
    '------------------------------------------------------------------------------------------------------

    weeksDifference = VBA.DateDiff("ww", startDate, endDate, firstDayOfWeek, VBA.vbFirstFourDays)

End Function