Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org
FAQs

Terms of Use

Date/Time: Calculate Number of Working Days

Author(s)
Dev Ashish

(Q)    How do I calculate total number of working days between two dates?

(A)    Use the following function.

'*********** Code Start **************
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)
      	WholeWeeks = DateDiff("w", BegDate, EndDate)
      	DateCnt = DateAdd("ww", WholeWeeks, 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 = WholeWeeks * 5 + EndDays
End Function
'*********** Code End **************

© 1998-2002, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer