'********************************************************************************************************** ' Name: workingDaysDifference ' Author: mielk | 2014-02-10 ' ' Comment: Function to count the number of working days between two dates. ' Only Saturdays and Sundays are considered to be non-working days. Function doesn't ' recognize holidays. ' ' Parameters: ' baseDate Base date. ' comparedDate Date to be compared with the base date. ' ' ' Returns: ' Integer The number of working days between two dates. ' If [baseDate] is earlier than [comparedDate] the result is positive, otherwise the ' result is negative. ' ' ' ' --- Changes log ----------------------------------------------------------------------------------------- ' 2013-04-10 mielk Function created. '********************************************************************************************************** Public Function workingDaysDifference(baseDate As Date, comparedDate As Date) As Integer Const METHOD_NAME As String = "workingDaysDifference" '------------------------------------------------------------------------------------------------------ Dim weeksDifference As Integer '------------------------------------------------------------------------------------------------------ weeksDifference = VBA.DateDiff("ww", baseDate, comparedDate, vbMonday) workingDaysDifference = comparedDate - baseDate - (weeksDifference * 2) End Function '********************************************************************************************************** ' 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