- Home
·
- Miscellaneous
·
- Function accepts two dates, and returns the number of business days between them (as an integer). I
Function accepts two dates, and returns the number of business days between them (as an integer). I
Function accepts two dates, and returns the number of business days between them (as an integer). If date2 is a date before date1, function
Rate Function accepts two dates, and returns the number of business days between them (as an integer). I
(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 accepts two dates, and returns the number of business days between them (as an integer). I Comments
No comments yet — be the first to post one!
Post a Comment