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

Add number of working or business days

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 direct
date functions (which have also changed slightly). There's no room to
put the code in the margins :-), but there's enough room to put up a
few URL's. The zip file is a zipped A97 mdb file with a single module.

Zipped:

http://www.oakland.edu/~fortune/DirectDateFunctions.zip

Text:

http://www.oakland.edu/~fortune/DirectDateFunctions.txt

Syntax:

BusinessDateAdd(number, date, boolean)

number = number of business days to add
date = starting date
boolean = True when using observed holiday functions

Example:

BusinessDateAdd(10, #12/23/06#, False) =1/9/2007

Sample calculation:
12/23/06 Starting Date
12/24/06 Sunday
12/25/06 Christmas
12/26/06 Tue +1
12/27/06 Wed +1
12/28/06 Thu +1
12/29/06 Fri +1
12/30/06 Saturday
12/31/06 Sunday
1/1/07 New Year's Day
1/2/07 Tue +1
1/3/07 Wed +1
1/4/07 Thu +1
1/5/07 Fri +1
1/6/07 Saturday
1/7/07 Sunday
1/8/07 Mon +1
1/9/07 Tenth business day after 12/23/06

It considers a business day to be a weekday that is not a(n) (observed)
holiday.

James A. Fortune
CD********@FortuneJames.com

Jul 21 '06 #1
4 6132
DFS
That's nice work. Can I use your CountHolidays() code in my systems?
How about:

==================================================
Public Function CountWeekDays(dtStart as Date, dtEnd as Date) as Long

dim i as Long
CountWeekDays = 0

For i = dtStart To dtEnd
If Format(i, "ddd") <"Sat" And Format(i, "ddd") <"Sun" Then
CountWeekDays = CountWeekDays + 1
End If
Next i
End Function
==================================================
And now, using your CountHolidays() function:

MsgBox "Business days between " & dtStart & " and " & dtEnd: " & _
CountWeekDays(dtStart, dtEnd) - CountHolidays(dtStart, dtEnd, True)

==================================================
Whaddaya think?


CD********@FortuneJames.com wrote:
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 direct
date functions (which have also changed slightly). There's no room to
put the code in the margins :-), but there's enough room to put up a
few URL's. The zip file is a zipped A97 mdb file with a single
module.

Zipped:

http://www.oakland.edu/~fortune/DirectDateFunctions.zip

Text:

http://www.oakland.edu/~fortune/DirectDateFunctions.txt

Syntax:

BusinessDateAdd(number, date, boolean)

number = number of business days to add
date = starting date
boolean = True when using observed holiday functions

Example:

BusinessDateAdd(10, #12/23/06#, False) =1/9/2007

Sample calculation:
12/23/06 Starting Date
12/24/06 Sunday
12/25/06 Christmas
12/26/06 Tue +1
12/27/06 Wed +1
12/28/06 Thu +1
12/29/06 Fri +1
12/30/06 Saturday
12/31/06 Sunday
1/1/07 New Year's Day
1/2/07 Tue +1
1/3/07 Wed +1
1/4/07 Thu +1
1/5/07 Fri +1
1/6/07 Saturday
1/7/07 Sunday
1/8/07 Mon +1
1/9/07 Tenth business day after 12/23/06

It considers a business day to be a weekday that is not a(n)
(observed) holiday.

James A. Fortune
CD********@FortuneJames.com

Jul 21 '06 #2
DFS wrote:
That's nice work. Can I use your CountHolidays() code in my systems?
I tried to make the functions as general as possible. In another post
I point out the one of the remaining weaknesses of using observed
holidays is that sometimes observed holidays are changed by legal fiat
such as Christmas falling on Thursday being rerouted to being observed
on Friday. Otherwise, I see no reason not to use techniques like these
(be sure to test thoroughly).
>

How about:

==================================================
Public Function CountWeekDays(dtStart as Date, dtEnd as Date) as Long

dim i as Long
CountWeekDays = 0

For i = dtStart To dtEnd
If Format(i, "ddd") <"Sat" And Format(i, "ddd") <"Sun" Then
CountWeekDays = CountWeekDays + 1
End If
Next i
End Function
==================================================
And now, using your CountHolidays() function:

MsgBox "Business days between " & dtStart & " and " & dtEnd: " & _
CountWeekDays(dtStart, dtEnd) - CountHolidays(dtStart, dtEnd, True)

==================================================
Whaddaya think?
What you have in your messagebox corresponds with one of the cases of
the CountBusinessDays function, so it looks O.K. :-). For your
CountWeekDays function, looping through dates is alright if you're not
iterating over lots of records for a period of lots of years. I tried
to adjust the functions so that the computation speed does not depend
on the date span whenever possible.

James A. Fortune
CD********@FortuneJames.com

Jul 21 '06 #3
DFS
CD********@FortuneJames.com wrote:
DFS wrote:
>That's nice work. Can I use your CountHolidays() code in my systems?
What you have in your messagebox corresponds with one of the cases of
the CountBusinessDays function, so it looks O.K. :-). For your
CountWeekDays function, looping through dates is alright if you're not
iterating over lots of records for a period of lots of years. I tried
to adjust the functions so that the computation speed does not depend
on the date span whenever possible.
I just ran it for 1,000 years. It took 2 seconds on a P4-2ghz system.

Jul 21 '06 #4
DFS wrote:
CD********@FortuneJames.com wrote:
DFS wrote:
That's nice work. Can I use your CountHolidays() code in my systems?

What you have in your messagebox corresponds with one of the cases of
the CountBusinessDays function, so it looks O.K. :-). For your
CountWeekDays function, looping through dates is alright if you're not
iterating over lots of records for a period of lots of years. I tried
to adjust the functions so that the computation speed does not depend
on the date span whenever possible.

I just ran it for 1,000 years. It took 2 seconds on a P4-2ghz system.
O.K., I concede that your CountWeekDays function is perfectly adquate
for nearly every possible expected usage. But note that I have
included a CountWeekdays function in there as well. The speed increase
for large time spans with mine may not be very noticeable, but I don't
feel like my effort was wasted either. The goal of the functions is to
provide tools to enable people to accomplish more so I can't complain
about you seeing new ways to do things. I don't think I'm done adding
to their capabilities either. I'm glad you liked them.

James A. Fortune
CM********@FortuneJames.com

Jul 21 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tiernan | last post by:
Hi all I'm looking for a way to find the number of weekdays between 2 dates In my form I have three fields for a begin date (dd)(mm)(yyyy) and three for the end date (dd)(mm)(yyyy) Now these...
5
by: SimonC | last post by:
Help needed for a Javascript beginner. As above in the subject... i need a javascript to run this, but not in the form of a web-page. I want to calculate it between 2 fields in a database that...
7
by: Shuffs | last post by:
Could someone, anyone please tell me what I need to amend, to get this function to take Sunday as the first day of the week? I amended the Weekday parts to vbSunday (in my code, not the code...
10
by: Pavils Jurjans | last post by:
Hallo, It is know issue that due to the fact that computer has to store the real numbers in limited set of bytes, thus causing a minor imprecision from the decimal value that likely was stored....
29
by: james | last post by:
I have a problem that at first glance seems not that hard to figure out. But, so far, the answer has escaped me. I have an old database file that has the date(s) stored in it as number of days. An...
3
by: TS | last post by:
short x = 1; //this has build error saying missing conversion x = x + 2; Why can't you just add this? I guess the 1 is a literal that translates to an int32? How would I accomplish this...
4
by: shilpareddy2787 | last post by:
Hello, I have some total values, I want to calculate percenatge of these Total Values. I want to divide the total with No. Of working Days Excluding Saturdays and Sundays in a given period. ...
14
by: Tommy Jakobsen | last post by:
Hi. Is there a method in .NET that takes "year" as an argument and returns the total number of weeks in that year? For culture da-DK (Danish). Thanks in advance. Tommy.
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.