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

How do I calculate business days

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

--
Thanks,

Sam
Oct 29 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi Sam,

Search google and you'll find answers to that question.

Here's one that attempts to add week days. I haven't tried it myself (watch
for wrapping):

http://groups.google.com/group/micro...4ab250754c077e

--
Dave Sexton

"Sam" <Sa*@discussions.microsoft.comwrote in message
news:E8**********************************@microsof t.com...
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?

--
Thanks,

Sam

Oct 29 '06 #2

P: n/a
"Sam" <Sa*@discussions.microsoft.comwrote in message
news:E8**********************************@microsof t.com...
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?
In order to do this, you need to know two things:

1) which days are "normal" working days e.g. Monday to Friday in most of the
Western world, but of course this isn't the case in other regions...

2) which days are additionally non-working days - e.g. in the UK, these are
typically the eight annual "Bank Holidays"...

1) is easy because it (almost) never changes - having said that, for a short
period in the 1970s the UK introduced the "three-day week", so it *can*
change...

For 2) you need some sort of database.

I use SQL Server for this, and have several functions which calculate e.g.
next business day, previous business day, number of business hours between
two datetime variables etc... This means that the functionality is available
to every app which interfaces with SQL Server.
Oct 29 '06 #3

P: n/a
I did something like this in sql server. Like the previous
post mentionds, you've got to take into account
"special" days. Often times, you'll just have to hard code
for these. Sometimes, you are just better off being
able to adapt to "special" situations as well.

http://www.eggheadcafe.com/articles/20030626.asp

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/..._generator.asp

"Sam" <Sa*@discussions.microsoft.comwrote in message
news:E8**********************************@microsof t.com...
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?

--
Thanks,

Sam

Oct 30 '06 #4

P: n/a
"Sam" <Sa*@discussions.microsoft.comwrote in message
news:E8**********************************@microsof t.com...
>
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?
Two words: calendar table.

///ark
Oct 30 '06 #5

P: n/a
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
Oct 30 '06 #6

P: n/a

Mark Wilden wrote:
Two words: calendar table.
Mark,

I second that option. It's unbelievable how many benefits there are to
calendar tables. Calculating the number of business days between two
dates is just a teaser.

Brian

Oct 30 '06 #7

P: n/a
Brian & Mark,

Here, here. Further yet, you can normalize with different calendars in
one table. Investment banks do this all the time: each of over 20
exchanges have two different sets of holidays, one for when the bank is
open and one for when their backend systems run. They pay royally for
intact, formatted and correct data.

If you don't like it in a database, put it in XML or a flat file or
something. Just pull it out of your code. Good luck with any other
solution trying to "figure out" when holidays are; if you get that
working, package it and I'll point you to several banks who are willing
to pay for the data.
Stephan
Brian Gideon wrote:
Mark Wilden wrote:
Two words: calendar table.

Mark,

I second that option. It's unbelievable how many benefits there are to
calendar tables. Calculating the number of business days between two
dates is just a teaser.

Brian
Oct 30 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.