devxlogo

BusinessDateAdd – Adding or subtracting a number of business days from a date

BusinessDateAdd – Adding or subtracting a number of business days from a date

' Add or subtract a number of business days from a date' Example: Debug.WriteLine(BusinessDateAdd(#4/9/2003#, 5)) ' => 4/16/2003Function BusinessDateAdd(ByVal startDate As Date, ByVal days As Integer, _    Optional ByVal saturdayIsHoliday As Boolean = True) As Date    Do While days        ' increment or decrement the date        startDate = startDate.AddDays(Math.Sign(days))        ' check that it is a week day        If startDate.DayOfWeek  DayOfWeek.Sunday AndAlso (startDate.DayOfWeek _             DayOfWeek.Saturday Or Not saturdayIsHoliday) Then            ' days becomes closer to zero            days -= Math.Sign(days)        End If    Loop    Return startDateEnd Function

devx-admin

Share the Post: