How can I calculate weekdays eliminating holidays in access?

  • Thread starter Thread starter Guest
  • Start date Start date
You need a holiday table with an entry for every none working weekday. You
do not want to include a holiday that is on a Saturday or Sunday because it
will get reversed out twice, once for being a week end day and once for being
a holiday. Here is a function that will return the number of working days
between two dates including holidays and week end days.

Function CalcWorkDays(dtmStart As Date, dtmEnd As Date) As Integer

On Error GoTo CalcWorkDays_Error

'Calculates the number of days between the dates
'Add one so all days are included
CalcWorkDays = DateDiff("d", dtmStart, dtmEnd) - _
(DateDiff("ww", dtmStart, dtmEnd, 7) + _
DateDiff("ww", dtmStart, dtmEnd, 1)) + 1
'Subtract the Holidays
' CalcWorkDays = CalcWorkDays - DCount("*", "holidays", "[holdate]
between #" _
' & dtmStart & "# And #" & dtmEnd & "#")

CalcWorkDays_Exit:

On Error Resume Next
Exit Function

CalcWorkDays_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure CalcWorkDays of Module modDateFunctions"
GoTo CalcWorkDays_Exit

End Function
 
Back
Top