Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 30th, 2008, 03:40 PM
Authorized User
Join Date: Apr 2005
Location: , , USA.
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default DateDiff to exclude weekends and holidays


I am working on an On Time Delivery Report that is generated on a monthly basis. The form specifies a single customer name and the date fields are From: and To: Ie. From 12/01/07 to 12/31/07. I need to count workdays only. Weekends and Holidays need to be excluded. There can be as many as 100 orders for a specific customer any given month. Each order appears on a separate line on the report.

I placed the following code in the On Format field of the report

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

Dim WorkDays As String

WorkDays = DateDiff("d", Me.JobEntryDateText, Me.DDate)

Me.Days.Value = WorkDays

End Sub

"d" gives me the total days (counting the weekends and holidays) example - 12/21/06 to 01/03/07 = 13 days

"w" gives me the number of full 7 day weeks - example 12/21/06 to 01/03/07 = 1

Any help will be appreciated! Thanks

D. Bartelt
D. Bartelt
Reply With Quote
  #2 (permalink)  
Old April 8th, 2008, 12:22 PM
Authorized User
Join Date: Apr 2005
Location: , , USA.
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts

Okay...Do I need to be using a different function than the DateDiff function?

Any suggestions?


D. Bartelt
Reply With Quote
  #3 (permalink)  
Old April 12th, 2008, 05:14 PM
Authorized User
Join Date: Jan 2006
Location: , , .
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts

Here's a function you can put in a standard module.
Public Function WorkingDays(StartDate As Date, EndDate As Date) As Integer
'-- Return the number of WorkingDays between StartDate and EndDate
On Error GoTo err_workingDays

Dim intCount As Integer

If IsDate(StartDate) And IsDate(EndDate) Then
   If EndDate >= StartDate Then

      intCount = 0
      Do While StartDate < EndDate
         StartDate = StartDate + 1
         If Weekday(StartDate, vbMonday) <= 5 Then
      '-- Use the following code if you have a "Holiday" table
'         If Weekday(StartDate, vbMonday) <= 5 And _
            IsNull(DLookup("[Holiday]", "tblHolidays", _
            "[HolDate] = " & Format(StartDate, "\#mm\/dd\/yyyy\#;;;\N\u\l\l"))) Then

            intCount = intCount + 1
         End If
      WorkingDays = intCount
      WorkingDays = -1  '-- To show an error
   End If
   WorkingDays = -1  '-- To show an error
End If

   Exit Function

   MsgBox "Error No:    " & Err.Number & vbCr & _
   "Description: " & Err.Description
   Resume exit_workingDays

End Function
HTH RuralGuy (RG for short) acXP WinXP Pro
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Date diff excluding holidays and weekends Altonjain Classic ASP Professional 0 February 9th, 2006 12:56 AM
DateDiff?? ( w/o weekends... ) underscore10304 Access VBA 7 January 24th, 2006 08:55 AM
Exclude Nodes seanhaggerty XSLT 1 February 3rd, 2005 06:00 AM
Exclude Certain Forms Ben Horne Access VBA 11 March 16th, 2004 03:06 PM
Calculate Workdays minus holidays woodan Access 1 February 11th, 2004 04:17 PM

All times are GMT -4. The time now is 08:22 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.