AH.. Got it:
Finally... here's code that will calculate the number of elapsed work days between two dates. It will account for New Years, Memorial Day, July 4th, Labor Day, Thanksgiving and Christmas as well as all Saturdays and Sundays.
The code is also listed for Easter .. though you don't need it because it's on Sunday which is already counted.
To use it you simply:
iElapsedDays=workdays(#11/20/2003#,#11/27/2003#)
This would result in iElapsedDays = 4 which is correct since Thanksgiving falls in that range.
Also resulting in 4 work days:
workdays(#11/22/2003#,#11/29/2003#) - 22nd is Saturday so toss out 3 WE days and 1 holiday = 7-3=4
workdays(#11/21/2003#,#11/29/2003#) - you don't count the day you begin on for elapsed stats so again 7-3=4
workdays(#11/21/2003#,#11/30/2003#) - 30'th is a WE so 8 - 3 WE days - 1 Holiday =4
workdays(#11/21/2003#,#11/28/2003#) - 7days - 2 WE days - 1 Holiday =4
workdays(#11/17/2003#,#11/22/2003#) = 4 Elapsed days. 5 - 1 WE day = 4
workdays(#11/16/2003#,#11/22/2003#) = 5 Elapsed days because Monday is day 1.. so 6 - 1 WE days = 5... we only count 1 WE day because the 16th is the starting day, which is never counted for elapsed days.
Function WorkDays(BegDate As Date, EndDate As Date) As Integer
WorkDays = (DateDiff("d", BegDate, EndDate)) - Holidays(BegDate, EndDate)
End Function
Public Function Holidays(ByVal BegDate As Date, ByVal EndDate As Date) As Integer
Dim HolidayCount As Integer
Dim iDays As Integer
Dim iDay As Integer
Dim dCurrDate As Date
iDays = DateDiff("d", BegDate, EndDate)
For iDay = 1 To iDays
dCurrDate = DateAdd("d", iDay, BegDate)
'Only interested in Week Days
If WeekDay(dCurrDate) > 1 And WeekDay(dCurrDate) < 7 Then
'--------------------
'New Years Day
If DatePart("y", dCurrDate) = 1 Then HolidayCount = HolidayCount + 1
'--------------------
'EASTER - Not needed but man is it cool
' Also note that it will never count Easter because it's on SUNDAY.
' If lYear <= 0 Then
' Dim dEaster As Date
' lYear = DatePart("yyyy", dCurrDate)
' Dim lYear As Long
' Dim a As Long, b As Long, c As Long, d As Long
' Dim e As Long, g As Long, h As Long, j As Long, k As Long
' Dim l As Long, m As Long, n As Long, p As Long
'
' a = lYear Mod 19
' b = lYear \ 100
' c = lYear Mod 100
' d = b \ 4
' e = b And 3
' g = ((8 * b) + 13) \ 25
' h = ((19 * a) + b - d - g + 15) Mod 30
' j = c \ 4
' k = c And 3
' m = (a + (11 * h)) \ 319
' l = ((2 * e) + (2 * j) - k - h + m + 32) Mod 7
' n = (h - m + l + 90) \ 25
' p = (h - m + l + n + 19) And 31
' dEaster = DateSerial(lYear, n, p)
' End If
' If dCurrDate = dEaster Then HolidayCount = HolidayCount + 1
'--------------------
'Memorial Day
If DatePart("m", dCurrDate) = 5 Then
If DatePart("w", dCurrDate) = 2 Then
If CLng(DatePart("d", dCurrDate) / 7) = 4 Then HolidayCount = HolidayCount + 1
End If
End If
'--------------------
'Independance Day
If DatePart("m", dCurrDate) = 7 Then
If DatePart("d", dCurrDate) = 4 Then HolidayCount = HolidayCount + 1
End If
'--------------------
'Labor Day
If DatePart("m", dCurrDate) = 9 Then
If DatePart("w", dCurrDate) = 2 Then
If CLng(DatePart("d", dCurrDate) / 7) < 1 Then HolidayCount = HolidayCount + 1
End If
End If
'--------------------
'THANKSGIVING
If DatePart("m", dCurrDate) = 11 Then
If DatePart("w", dCurrDate) = 5 Then
If DatePart("d", dCurrDate) >= 23 Then HolidayCount = HolidayCount + 1
End If
End If
'--------------------
'CHRISTMAS
If DatePart("m", dCurrDate) = 12 Then
If DatePart("d", dCurrDate) = 25 Then HolidayCount = HolidayCount + 1
End If
Else
'Weekend Day
HolidayCount = HolidayCount + 1
End If
Next
Holidays = HolidayCount
End Function