On Sat, 28 Oct 2006 23:38:01 -0700, Sam <Sa*@discussions.microsoft.comwrote:
>Hi,
I use C# in my ASP.NET projects. Here's what I need to do: I want to add x
business days to a given date i.e. add 12 business days to today's date. What
is the best, fastest and most efficient way for me to do this?
This is an old time (all time) industrial engineering problem.
Since you can't really calculate this easily the solution is usually done by
having a lookup table that represents a calendar. If you were in a
manufacturing environment you would call the table a Manufacturing Day Calendar
(MDAY Calendar).
The calendar is constructed in the manner below:
Mon 11/20/2006 MDAY = 1
Tue 11/21/2006 MDAY = 2
Wed 11/22/2006 MDAY = 3
Thu 11/23/2006 MDAY = 3 Holiday
Fri 11/24/2006 MDAY = 3 Also holiday at some businesses ;o)
Sat 11/25/2005 MDAY = 3 weekend
Sun 11/26/2006 MDAY = 3 weekend
Mon 11/27/2006 MDay = 4
Work days are given numbers as shown above. A non-working day gets the same
number as the day before.
If you build a lookup table containing this data you can select the rows with
the beginning and ending dates and subtract the beginning date's MDAY from the
ending date's MDAY and you have the number of working day between the two.
You can write code that uses the table to get the MDAY numbers of dates to do
these calculations.
Typically you would choose a day in the past to begin the numbering sequence.
many aircraft factories in the US use this method of calculating span days
(number of work days in a task) and the MDays begin at #1 on a date near the
beginning of World War II. They just keep incrementing them each year after
negotiating holidays with the unions.
Good luck with your project,
Otis Mukinfus
http://www.arltex.com http://www.tomchilders.com