Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB7
Expertise: Intermediate
Jun 9, 2003

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/2003

Function 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 startDate
End Function
Marco Bellinaso
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date