Skip to content

Instantly share code, notes, and snippets.

@sholsinger
Created April 15, 2011 15:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sholsinger/921871 to your computer and use it in GitHub Desktop.
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.
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