By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,491 Members | 858 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,491 IT Pros & Developers. It's quick & easy.

Add number of working or business days

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.