• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 451
  • Last Modified:

VB.NET: How to find the number of weekend days (or bussiness days) between 2 dates

Given 2 date time picker controlls, one for a startDate and the other one for an endDate, how would I go about finding either the number of weekend days or bussiness days between 2 given dates (it doesn't matter which since I can just substract the those days from the total number of days between the two dates) Your help on this issue will be greatly appreciated.
0
isrxl
Asked:
isrxl
1 Solution
 
iboutchkineCommented:
Function BusinessDateDiff(ByVal startDate As Date, ByVal endDate As Date,
 Optional ByVal saturdayIsHoliday As Boolean = True) As Integer
    Dim incr As Integer

    ' incr can be +1 or -1
    If startDate < endDate Then incr = 1 Else incr = -1

    Do Until startDate = endDate
        ' skip to previous or next day
        startDate = startDate.AddDays(incr)
        If startDate.DayOfWeek <> DayOfWeek.Sunday AndAlso _
            (startDate.DayOfWeek <> DayOfWeek.Saturday Or Not
saturdayIsHoliday) Then
            ' if it's a weekday add/subtract one to the result
            BusinessDateDiff += incr
        End If
    Loop
    ' when the loop is exited the function name contains the correct
result
End Function
0
 
isrxlAuthor Commented:
Thank you very much iboutchkine, that's short and sweet.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now