VBScript – Add Working Days to Date

The VBScript “DateAdd” allows you to add days to a date. The Syntax is:

DateAdd(interval,number,date)

For example, to add 4 days, you use:

DateAdd(d,4,Now())

The issue is, this doesn’t include weekends. However I fell across this solution thanks to Sholsinger:

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

To use this function, call it as follows:

BusinessDayAdd(4,Now())

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.