Adding/subtracting weekdays (1 Viewer)

Status
Not open for further replies.

raskew

AWF VIP
Local time
Today, 02:57
Joined
Jun 2, 2001
Messages
2,734
The following will allow the user to add/subtract weekdays (Mon - Friday) from a specified (US short-date) date. Note that holidates aren't considered.
Code:
Function UpBusDays3(pStart As Date, _
                    pnum As Integer, _
                    Optional pAdd As Boolean = True) As Date
'*******************************************
'Purpose:   Add or subtract business days
'           from a date
'Coded by:  raskew
'Inputs:    1) +) ? UpBusDays3(#2/17/06#, 3, True)
'           2) -) ? UpBusDays3(#2/22/06#, 3, False)
'Output:    1) +) 2/22/06
'           2) -) 2/17/06
'*******************************************
                    
Dim dteHold As Date
Dim i       As Integer
Dim n       As Integer

    dteHold = pStart
    n = pnum
    For i = 1 To n
       If pAdd Then  'add days
          dteHold = dteHold + IIf(WeekDay(dteHold) > 5, 9 - WeekDay(dteHold), 1)
       Else          'subtract days
          dteHold = dteHold - IIf(WeekDay(dteHold) < 3, Choose(WeekDay(dteHold), 2, 3), 1)
       End If
    Next i
    UpBusDays3 = dteHold
    
End Function

Bob
 
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom