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