Code for WORKDAY()

Avaughan

New member
Local time
Today, 23:12
Joined
Nov 30, 2001
Messages
6
I need to calculate the number of workdays between two fields in VB.

Is there afunction or how should I do it?
I am launching the following as an event procedure After Update.

Me![Days] = Me![End Date] -Me![Start Date] gives me total days. I just need work days.


Thanks
 
Function Work_Days(BegDate As Variant, EndDate As Variant) As Integer

' Note that this function does NOT account for holidays.

Dim WholeWeeks As Variant
Dim DateCnt As Variant
Dim EndDays As Integer

BegDate = DateValue(BegDate)
EndDate = DateValue(EndDate)
DateCnt = BegDate
EndDays = 0

Do While DateCnt <= EndDate

If Format(DateCnt, "ddd") <> "Sun" And _
Format(DateCnt, "ddd") <> "Sat" Then
EndDays = EndDays + 1
End If
DateCnt = DateAdd("d", 1, DateCnt)
Loop
Work_Days = EndDays

End Function
 

Users who are viewing this thread

Back
Top Bottom