473,387 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Is there a DateDiff function that counts business days?

Seth Schrock
2,965 Expert 2GB
I am trying to create a report that tells us how long it takes work to get between stages. Since we don't work on Sundays or federal holidays, I was hoping to omit those days from the count. We do work Saturdays so they would need to be included. Basically, I want a count of 1 if it left stage 1 on Saturday and left stage 2 on Monday. Is this possible, or do I just need to tell management that the count includes Sundays and holidays?
Dec 6 '12 #1

✓ answered by zmbd


4 18910
ADezii
8,834 Expert 8TB
I created a simple Function that will count the number of Workdays, including Saturdays, but not Sundays and Federal Holidays. Create a Table named tblHolidays with a single DATE/TIME Field named [Date]. Populate this Table with any and all work related Holidays, then execute the Code
Expand|Select|Wrap|Line Numbers
  1. Public Function fCalcWorkingDays(dteStartDate As Date, dteEndDate As Date) As Integer
  2. Dim intCount As Integer
  3.  
  4. intCount = 0
  5.  
  6. Do While dteStartDate <= dteEndDate
  7.   Select Case Weekday(dteStartDate)
  8.     Case Is = 1
  9.       'It's a Sunday, do nothing
  10.     Case Is = 2, 3, 4, 5, 6, 7      'Monday thru Saturday
  11.       'is it a Holiday as posted in tblHolidays?
  12.       If DCount("*", "tblHolidays", "[Date] = #" & dteStartDate & "#") < 1 Then     'NOT Holiday
  13.         intCount = intCount + 1
  14.       End If
  15.   End Select
  16.     dteStartDate = dteStartDate + 1
  17. Loop
  18.   fCalcWorkingDays = intCount
  19. End Function
Executing fCalcWorkingDays(#12/1/2012#,#12/31/2012#) will return the Value 25 since there are 5 Sundays in December as well as Christmas.
Dec 6 '12 #3
NeoPa
32,556 Expert Mod 16PB
Logically, Access cannot be programmed to know about federal holidays as holidays around the world cannot be accurately predicted in advance. They change for various reasons and Access would need to be able to handle all holidays for all countries if it were to offer that functionality. I wasn't involved in designing Access but I'd be prepared to bet that facility isn't available, as it wouldn't make sense.

That said, the number of days in a date range is pretty easily available, so starting with that is a decent basis to work from (in order to produce your own function to return this value). Knowing the number of days in the range and the start day of the week you can easily determine how many Sundays fall within that range. All that's left now is for the number of public holidays to be subtracted from the number. You have a date range, remember.

You now need to maintain a table of public holiday dates in your database (or even some central BE database that all your projects can share). With that available you can either look up all the values in the date range or, more efficiently, link that table into any query you're using to ensure the relevant dates are already available. Be careful of Sundays. They either need to be omitted completely from the table or the function will need to ignore them when it determines the public holidays to subtract.

So, this is certainly not as trivial as finding the number of days in a date range, but nor is it excessively complicated. It does, however, mean that there is a new responsibility of ensuring this new table is always up-to-date and adequately populated.
Dec 6 '12 #4
Seth Schrock
2,965 Expert 2GB
That is exactly what I was needing, but I certainly didn't expect it to be that complicated. Thankfully Copy/Paste worked pretty well. I just had to change the table name to fit my database, but other than that it worked perfectly.
Dec 17 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Anthony Robinson | last post by:
Is anyone aware of a function (system or user defined) that will calculate business days? For instance: I have a column in as table called DATE. I want to be able to add five business days to that...
1
by: info | last post by:
Can some one show me how to use the datediff function where the dates are being supplied through an access db. For instance, a recordset would contain these fields: DateAssigned, DateDue,...
5
by: mcbill20 | last post by:
Hello all. I have a really basic question that I hope someone has a better answer for. I apologize in advance-- I know this is probably a really basic question but I am used to Oracle rathern than...
4
by: CDMAPoster | last post by:
I'm starting to come up with a version of DateAdd that I call BusinessDateAdd that adds the selected number of business days. It's still in preliminary form (needs testing) and interacts with my...
7
by: Sam | last post by:
Hi, I use C# in my ASP.NET projects. Here's what I need to do: I want to add x business days to a given date i.e. add 12 business days to today's date. What is the best, fastest and most...
3
by: DumStudent | last post by:
I need help with what to write for my DateDiff Function to work properly between two datetimepicker boxes to give 'days' results. This is what I have and it works except I can't have the intDate1 to...
1
by: KMEscherich | last post by:
Using Access '97 Hi there. I have a field that uses a DateDiff function to count the number of days between a DATE field and DATE(), is there a way to have the counter stop counting days when the...
7
by: JenM | last post by:
Hi. I am a novice user. I am using the datediff function in a query. I am trying to calculate the number of week days between two dates. When I use "m" as the interval, the number of weeks is...
8
by: =?Utf-8?B?QWw=?= | last post by:
I am working in vb2005. how can I calculate business days (not including holidays and weekends) between 2 dates? thanks Al
5
FishVal
by: FishVal | last post by:
IMHO, the following is not a how-to-do instruction to solve a particular problem but more a concept-proof stuff demonstrating possibilities of SQL. So, let us say the problem is to calculate...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.