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

# 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
1 Solution

Commented:
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
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
End If
Loop
' when the loop is exited the function name contains the correct
result
End Function
0

Author Commented:
Thank you very much iboutchkine, that's short and sweet.
0

## Featured Post

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