BusinessDateDiff

Number of Business days between two dates.
Note that it doesn't take Christmas, Easter and other holidays into account

CodeFunctionName
What is this?

Public

Not Tested

Imported
Function BusinessDateDiff(StartDate, EndDate, SaturdayIsHoliday)
    Dim incr
    StartDate = CInt(StartDate) ' ensure we don't take time part into account
    EndDate = CInt(EndDate)
    If StartDate < EndDate Then incr = 1 Else incr = -1 ' incr can be +1 or -1
    Do Until StartDate = EndDate
        StartDate = StartDate + incr ' skip to previous or next day
        If Weekday(StartDate) < > vbSunday And (Weekday(StartDate) < > vbSaturday Or Not SaturdayIsHoliday) Then
            BusinessDateDiff = BusinessDateDiff + incr ' if it's a weekday add/subtract one to the result
        End If
    Loop
End Function

StartDate, EndDate, SaturdayIsHoliday

Views 145

Downloads 44

CodeID
DB ID

ANmarAmdeen
610
Attachments
Revisions

v1.0

Wednesday
October
25
2023