Hello. I am using the below code courtesy of The Smiley Coder which works beautifully. I would now like to carve out holidays in addition to the weekends. I believe I will have to create a table of the holidays, but I'm not certain how to work it into the code. Any assistance is greatly appreciated.
Public Function addWorkDays(Dat eInput As Date, intDays As Integer) As Date
'Function that only adds days if they are workdays (monday-friday)
'Holidays are not excluded.
'Setup a working date
Dim myDT As Date
myDT = DateInput
'Setup number of days remaining to add
Dim intDaysRemain As Integer
intDaysRemain = intDays
'Now add days 1 at a time,
' while counting down intDaysRemain,
' but only if day is a working day
Do Until intDaysRemain = 0
myDT = DateAdd("d", 1, myDT)
Select Case Weekday(myDT)
Case vbMonday, vbTuesday, vbWednesday, vbThursday, vbFriday
intDaysRemain = intDaysRemain - 1
Case vbSaturday, vbSunday
'Don't modify intDaysRemain
End Select
Loop
'Return answer
addWorkDays = myDT
End Function
2 1913
I think the simplest way to do that, given your existing code, is to create a table of holidays that your organization observes. We then just need to add a check to see if any given date is in that table.
I created a table called HolidayTable with two fields: HolidayName and HolidayDate, and filled it with a couple entries: -
HolidayName HolidayDate
-
New Year's 01/01/2011
-
Memorial Day 05/30/2011
-
4th of July 07/04/2011
-
Then add a couple lines to your code (added lines in bold): -
Select Case Weekday(myDT)
-
Case vbMonday, vbTuesday, vbWednesday, vbThursday, vbFriday
-
'Check to see if holiday
-
If DCount(1, "HolidayTable", "HolidayDate = #" & myDT & "#") < 1 Then
-
intDaysRemain = intDaysRemain - 1
- End If
-
Case vbSaturday, vbSunday
-
'Don't modify intDaysRemain
-
End Select
-
This should now ignore any dates that are in your table. -
?addWorkDays(#5/29/2011#, 7)
-
6/8/2011
-
-
?addWorkDays(#5/30/2011#, 7)
-
6/8/2011
-
-
?addWorkDays(#5/31/2011#, 7)
-
6/9/2011
-
Your code works perfectly! Thank you so much.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: mene |
last post by:
I have a field that contains date information, and sometimes time
information as well. I would like to be able to take that date and do a
calculation on it. Here are some examples of what is in the field:
01/12/2003 5:04:00 PM
24/11/2003
19/05/2003 6:30:00 AM
How can I take that date, then do a calculation like minus 5 days from the
date. I understand that I am to use the GETDATE() function, but below is
|
by: lduperval |
last post by:
Hi,
I`m trying to do date calculations in three types of time zones: local,
GMT and specified. The issue I am facing is that I need to be able to
specify a date in the proper time zone, and I`m having a heck of a time
doing so.
I have created a form where I use drop downs do specify year, month,
date, hour, minute and seconds. When the form is loaded, the dropdowns
have to display the proper values for the current time zone type. This
|
by: Joe Jax |
last post by:
I have some date calculations that add a time span to a date. The problem
is, when I add a time span that is a whole number of days to a date, the
result can be +/- 1 hour due to daylight savings. Is there anyway to disable
this?
|
by: Mark Lees |
last post by:
I need some help setting up some date caluclations.
Fields Include:
A. DOB "date of birth"
B. IFSPOrginal "Date IFSP is entered"
C. IFSPRedo "Date 12 months into the future from
IFSPOrginal"
D. 2yrTransistion "Date 2yrs into the futre from DOB"
I'm having difficulty creating the expressions for the (C)IFSPRedo and
|
by: Roffee |
last post by:
Hi.
I'm a bit confused about date functions in Access. I need the program to
calculate a new date that lays 15 days ahead of a given date in a table. I
studied the datediff function, but as I see it, it only returns a number of
days (or other time period) between two dates. I need a future date as
output.
Hints anyone?
| |
by: Julie Wardlow |
last post by:
Help!
I am calculating a future date using the DateAdd function in a query (the
calculation also involves an IIf statement), and have managed to get this
formula to produce the required result.
I then want to search through the records and select those with dates (as
caluclated above) within a user defined range, and so I am using a parameter
query. However, this query returns dates outside of the range and appears to
have particular...
|
by: Wayne |
last post by:
Hi all
I'm trying to calculate the number of days (or workdays) between 2 given
dates that do not include weekend days or public holidays
(public holidays are user defined from a dbase, have a start date & an end
date & may span a weekend)
If a start date (workday) & an end date (workday) are on the same day then
the number of workdays will equal zero
Some eg's.
|
by: Miguel Arenas |
last post by:
In VB6.0 I Did This operation with dates.
Dim d as String
D=Date
D=D-1
or
D=D+1
In Vb.2003
Dim d As String
|
by: Charlie Brookhart |
last post by:
I am creating a program that involves having to find the difference between
two dates and converting it to a number to be used for calculations. The
problem is that the way it is setup, VB is not doing anything with the dates
that I have selected. I hope that someone here can help me figure out why it
is not working what I have to do to make it work.
This the code I have for the date calculations.
txtNumberOfDays.text =...
|
by: arggg |
last post by:
I have a table with with Last_Modified field as VARCHAR(55) which stores dates in the format of 2/15/08 1:34 PM. What I need to do is query the database and select ALL rows that have the Last_Modified field >= 6 days from the current date/time. It appears I will need to convert the dates so I can use the mysql calculations but I'm unsure where to begin on this.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |