VB - Find workdays between 2 dates
Usually this is done with loops, but not anymore
VB Code:
Private Sub Form_Load()
Dim EndDate As Date, StartDate As Date
StartDate = #2/23/2006#
EndDate = #2/28/2006#
Debug.Print FindWorkDays(StartDate, EndDate)
End Sub
Private Function FindWorkDays(ByVal StartDate As Date, ByVal EndDate As Date) As Long
'
' Made by Michael Ciurescu (CVMichael from vbforums.com)
' Original Thread: [url]http://www.vbforums.com/showthread.php?t=390857[/url]
'
If StartDate > EndDate Then
FindWorkDays = -1
Else
FindWorkDays = Fix(EndDate - StartDate) - Fix(Fix(EndDate - DateAdd("d", -Weekday(StartDate) + 2, StartDate)) / 7) * 2
End If
End Function