473,400 Members | 2,145 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,400 software developers and data experts.

Date formula to count days between two dates but not count holidays or weekends

Hello,

I am a novice Access developer and my boss asked me to build a database and I said yes. Now I realized the bite is way too big and I'm trying not to choke ;-)

And what's worse, he does not want me to use VBA (thank god, one less thing for me to tear my hair out about). So I am struggling to figure out how to do this:

Count the number of days between two dates and not count holidays and weekends.

I googled it up and talked with a couple of folks, they all said VBA is the key but my boss says it can be done without VBA.

Do anyone know how I can do this without using VBA? any help would so much appreciated. Maybe I will finish the project with some hair intact!

Matt
Oct 13 '09 #1

✓ answered by FishVal


9 12434
Denburt
1,356 Expert 1GB
All I can do is hope I can help, especially when it comes to the hair, I know how it feels to lose it.

Do you have a table set up for the Holidays or anything? If so please display your table structures and relationships.

Do you have a Holidays table? If not I think we should start with the holidays table and go from there. Set up a table with an autonumber field for a primary field then list your holiday names and a field for the Holiday dates (you may not want to use this as a date field since some holidays might fall on the first Monday of a month etc. so try to take this all into account.
Oct 13 '09 #2
Thank you so much cuz, I love my hair ;-)

In Access 2007:

I already set up a holiday table with all holidays from 2007 to 2012. however, I use data/time field for all holiday dates so should I change it to text field? Also, I looked at the relationship and there's no connection to any forms, queries or forms. It's empty.

I know the next step is to create a holiday query but after that I am completely lost to what to do.
Oct 13 '09 #3
Denburt
1,356 Expert 1GB
Count the number of days between two dates and not count holidays and weekends.
Well you didn't provide a table structure so... Are the two dates in one table on two different records or is it in one table in two different fields, or are the dates in two different tables?

Quick stab, if the two dates are in one table in two different fields try this as a start for your select query. Note this is only to determine if either date falls on a weekend, if so we need to make an adjustment for that however if you are sure neither date falls on a weekend then we can skip this (let me know). Just go to SQL view on a new query and modify the following as necessary:

Expand|Select|Wrap|Line Numbers
  1. Select IsItaWeekDay:iif(weekday(Date1)=1 or weekday(Date1)=7,iif(weekday(Date2)=1 or weekday(Date2)=7,"Weekend","Not") From YourTable
Oct 13 '09 #4
NeoPa
32,556 Expert Mod 16PB
@Scholar81
It can Matt, but not without stored holidays, and not remotely easily. It doesn't sound like your boss has a very good understanding of the complications involved. I wouldn't even want to take anyone but an experienced programmer (or DB designer) through this to be perfectly honest.

On the plus side, though it's easier using VBA, it's not a whole hell of a lot easier to be fair.

This problem comes up fairly frequently. Often introduced by "I know this must be easy but ...".

The technique would be to determine (arithmetically) how many weekdays exist between the two dates. From this you would need to subtract those holidays found in your holiday table which both :
  1. Occur on a weekday.
  2. Occur between the start and end dates.
Oct 13 '09 #5
NeoPa
32,556 Expert Mod 16PB
@Scholar81
Date/Time is probably better.

It may help if you post the Meta-Data (info about the layout / structure) for your table in the same way as I use in my example. Click on the Reply button and you will have access to all the codes I've used. PK & FK stand for Primary Key & Foreign Key respectively. Never use TABs in this as the layout gets mucked up. Use spaces and all is fine.
Table Name=[tblStudent]
Expand|Select|Wrap|Line Numbers
  1. Field           Type      IndexInfo
  2. StudentID       AutoNumber    PK
  3. Family          String        FK
  4. Name            String
  5. University      String        FK
  6. Mark            Numeric
  7. LastAttendance  Date/Time
Oct 13 '09 #6
I am sorry... I forgot to include the file structure and everything.

All pertinent date fields are in one table "Data Collection". The pertinent date fields names are [CAR Discovered Date] and [CAR TO EVMC Date (initial)]

The holiday table is titled Holidays
The query holiday table is titled qryHolidays

So based on the formula you gave me.

I am comfortable with design view so I'll just do it from there instead of SQL view if you dont mind ;-) I am so new at this.

I go to the Data Collection query table and input this in a new column. Weekday:
Expand|Select|Wrap|Line Numbers
  1. Weekday: iif(weekday[CAR TO EVMC Date (initial)])=1 or weekday([CAR TO EVMC Date (initial)])=7, iff(weekday[CAR Discovered Date])=1 or weekday([CAR Discovered Date])=7, "weekend", "Not")
That makes total sense. #1 is sunday while #7 is saturday because Access by default starts the week on Sunday or 1.

I knew iif was the key but wasnt sure how to write it. Think of me as your 28 year old 1st grade student struggling to learn English ;-)

I hope we can do this tonight so I can tell my boss tmw morning that I did it (sort of)

Matt
Oct 13 '09 #7
NeoPa
32,556 Expert Mod 16PB
I'm off for tonight, but before I go you guys should know that the Weekday() function takes a parameter whereby you can specify the start day of the week. Checking for weekend days can be done in a single check (<2) if you specify Saturday as the week start.

Have fun.
Oct 14 '09 #8
NeoPa
32,556 Expert Mod 16PB
Nice work Fish :)

I've sent you a PM in relation to this (The article - not this thread per se).

PS. I've also locked the article thread to avoid more nooby posters dropping their questions in there in future (They can post a new thread with a link possibly, as they're supposed to do).
Oct 14 '09 #10

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

Similar topics

5
by: mitchchristensen | last post by:
I have a transaction log that tracks issues from a call center. Each time an issue is assigned to someone else, closed, etc. I get a time stamp. I have these time stamps for the beginning of an...
18
by: jimfortune | last post by:
I have an A97 module called modWorkdayFunctions in: http://www.oakland.edu/~fortune/WorkdayFunctions.zip It allows the counting of workdays taking into consideration up to 11 U.S. holidays. ...
7
by: No bother | last post by:
I have a table which has, among other fields, a date field. I want to get a count of records where certain criteria are met for, say, three days in a row. For example: NumWidgets Date...
2
by: MLH | last post by:
With a table of holidays and A97's date fn's - how best to count weekends and holidays between two dates? My holiday table has 4 fields. I will be adding records to it each year as info becomes...
6
by: Jana | last post by:
Greetings Access Gurus! I am working on an app to send batch transactions to our bank, and the bank requires that we place an effective date on our files that is 'one business day in the future,...
4
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi, I have a web application that I need to add 3 days to the Now day, but need to make sure that I skip weekends and holidays. For example if Now is friday, 3 days + now should be tuesday,...
11
by: Connie via AccessMonster.com | last post by:
Hi Access Building Friends, I am building a database for a manufacturer who needs to know the projected End_Date of each job. I know the Start_Date and the total days required to do the job. ...
1
by: trixxnixon | last post by:
This code omits weekends, holidays and returns a due date as well as the number of business days due. it also adds an extra day to the reqest if it was submitted after 5:00. as you can see that...
8
by: trixxnixon | last post by:
I know this topic is a veritable dead horse, but I have to ask, because I am unable to find something that is close to my scenario that I can completely understand. I have a start date field ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.