Created
April 15, 2011 15:20
-
-
Save sholsinger/921871 to your computer and use it in GitHub Desktop.
Visual Basic Script for doing "working day" arithmetic. Use this function to add or subtract business days from a VBScript date object.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function BusinessDayAdd(delta, dt) | |
dim weeks, days, day | |
weeks = Fix(delta/5) | |
days = delta Mod 5 | |
day = DatePart("w",dt) | |
If (day = 7) And days > -1 Then | |
If days = 0 Then | |
days = days - 2 | |
day = day + 2 | |
End If | |
days = days + 1 | |
day = day - 7 | |
End If | |
If day = 1 And days < 1 Then | |
If days = 0 Then | |
days = days + 2 | |
day = day - 2 | |
End If | |
days = days - 1 | |
day = day + 6 | |
End If | |
If day + days > 6 Then days = days + 2 | |
If day + days < 2 Then days = days - 2 | |
BusinessDayAdd = DateAdd("d", (weeks * 7 + days), dt) | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment