Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating the number of Weekdays between 2 dates. 2

Status
Not open for further replies.

mcnallyn

Technical User
Aug 22, 2006
4
GB
Hi there,

I'd like to be able to calculate the number of working days (Mon-Fri) between 2 dates using a query.

Any assistance would be greatly appreciated.
 
Place the following function into a code module, then, in your query pass your two dates into a call to this function...

Code:
Public Function NetWorkingDays(StartDate As Date, EndDate As Date) As Integer

   Dim intCount As Integer

   intCount = 0

   Do While StartDate <= EndDate
      Select Case Weekday(StartDate)
         Case 1, 7
            intCount = intCount
         Case 2, 3, 4, 5, 6
            intCount = intCount + 1
      End Select
   
      StartDate = StartDate + 1
   Loop

   NetWorkingDays = intCount

End Function
 
That would give you the working days, but just as a FYI - it does not account for holidays or the like. Check out faq705-4531 in the Access Modules: VBA Coding forum. Here I list some commonly used functions for different date calculations.....You might find some usefull. [smile]

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top