Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Add number of working or business days

26 views
Skip to first unread message

CDMAP...@fortunejames.com

unread,
Jul 21, 2006, 1:06:44 AM7/21/06
to
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
CDMAP...@FortuneJames.com

DFS

unread,
Jul 21, 2006, 1:34:28 AM7/21/06
to
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?

CDMAP...@fortunejames.com

unread,
Jul 21, 2006, 10:05:50 AM7/21/06
to
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
CDMAP...@FortuneJames.com

DFS

unread,
Jul 21, 2006, 10:33:01 AM7/21/06
to
CDMAP...@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.

CDMAP...@fortunejames.com

unread,
Jul 21, 2006, 11:08:19 AM7/21/06
to

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
CMDAP...@FortuneJames.com

0 new messages