I have a function that returns the number of Business Days elapsed between two dates minus Holidays that occur on business days.
I want to be able to return zero days when [StartDate] and or [EndDate] do not exist.
Here is the primary Function that I am using.
I have not included the CountHolidays Function as the message might be too long.
My end product will be a report that has 3 expressions for different Business Days counts.
Thus, most rows will not have all the date fields inputted as each row (project) is in different stages of completion.
Function GetWorkDays(ByVal StartDate As Date, ByVal EndDate As Date, ByRef CountHolidays As Boolean) As Long
Dim lngWeeks As Long
Dim tmpDate As Date
Dim intDays As Integer
lngWeeks = DateDiff(“w”, StartDate, EndDate)
tmpD
ate = DateAdd(“ww”, lngWeeks, StartDate)
intDays = 0
Do While tmpDate <= EndDate
If Weekday(tmpDate) vbSunday And Weekday(tmpDate) vbSaturday Then
intDays = intDays + 1
End If
tmpDate = DateAdd(“d”, 1, tmpDate)
Loop
If CountHolidays = True Then
GetWorkDays = lngWeeks * 5 + intDays – GetHolidayCount(StartDate, EndDate)
Else
GetWorkDays = lngWeeks * 5 + intDays
End If
End Function