- Home
·
- Miscellaneous
·
- Function returns the number of business days between two dates.
Function returns the number of business days between two dates.
Function returns the number of business days between two dates.
Rate Function returns the number of business days between two dates.
(1(1 Vote))
If DateDiff("d", date1, date2) < 0 Then ' Date1 is after Date2
BusinessDaysApart = -1
Else ' Date 1 is before Date2
If DateDiff("ww", date1, date2) = 0 Then ' Date1 and Date2 are in same week
If (Weekday(date1) >= 2 And Weekday(date1) <= 6) And (Weekday(date2) <= 6 And Weekday(date2) >= 2) Then 'Date1 and Date2 are between Mon and Fri
BusinessDaysApart = DateDiff("d", date1, date2)
Else ' either Date1 or Date2 is on the weekend
If DateDiff("d", date1, date2) > 4 Then ' Date1 and Date2 are more than 5 literal days apart
BusinessDaysApart = 4
' Date1 and Date2 can be a maximum of 4 business days apart if Date1 and Date2 are
' in the same week
Else
BusinessDaysApart = DateDiff("d", date1, date2)
End If
End If
ElseIf DateDiff("ww", date1, date2) > 0 Then ' Date1 and Date2 are not in the same week
BusinessDaysApart = DateDiff("d", date1, date2) - (DateDiff("ww", date1, date2) * 2)
' (subtract 2 days (weekends) from total literal days separating Date1 and Date2
' for every week separating Date1 and Date2)
End If
End If
End Function
Function returns the number of business days between two dates. Comments
No comments yet — be the first to post one!
Post a Comment