I\'m a SQL guy, but I need a function to calculate the number of weekdays between two dates in VB.NET. I don\'t need to worry about holidays. My attempts unfortunately have
I think this may help
Public Shared Function WeekEndsBetweenDates(ByVal StartDate As Date, ByVal EndDate As Date) As Integer
Dim wkday, wkend As Integer
For i As Integer = 0 To DateDiff(DateInterval.Day, StartDate, EndDate)
If DateAdd(DateInterval.Day, i, StartDate).DayOfWeek = DayOfWeek.Saturday Or DateAdd(DateInterval.Day, i, StartDate).DayOfWeek = DayOfWeek.Sunday Then
wkend += 1
Else
wkday += 1
End If
Next
Return wkend
End Function
Here, i returned "wkend" which is the weekend part of the variables in the function. Alternatively, you can change the returned value to "wkday" which is the number of weekdays between the selected dates. I hope this helps. It works for me though