473,226 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

How do I calculate business days

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
7 25929
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
"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
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
"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
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Anthony Robinson | last post by:
Is anyone aware of a function (system or user defined) that will calculate business days? For instance: I have a column in as table called DATE. I want to be able to add five business days to that...
8
by: =?Utf-8?B?QWw=?= | last post by:
I am working in vb2005. how can I calculate business days (not including holidays and weekends) between 2 dates? thanks Al
1
by: ArchMichael | last post by:
i need help again on calculating business days excluding holidays i have a field called assign date and i need to calculate 7 business days excluding holidays ( already have a table for holiday)...
2
by: rahulae | last post by:
help me with this I'm able to calculate total working days excluding weekends but how to exclude holidays,is there any other way apart from storing all the holidays in some table and not selecting...
17
by: trixxnixon | last post by:
i have a form with these fields Priority level: urgent critical standard business days: 1, 3, 15 date submitted: current date due date:
5
FishVal
by: FishVal | last post by:
IMHO, the following is not a how-to-do instruction to solve a particular problem but more a concept-proof stuff demonstrating possibilities of SQL. So, let us say the problem is to calculate...
0
debasisdas
by: debasisdas | last post by:
This function takes 2 dates as parameter and returns the number of working days. You need to add the list of holidays. (I have added a few as sample) CREATE OR REPLACE FUNCTION BUSINESS_DAYS...
1
by: chevyas123 | last post by:
How do i write a function to calculate business days excluding weekends and holidays in oracle? Actually i need to prepare a calendar for my monthly activities i.e activity x to be performed on 3rd...
3
by: PotatoChip | last post by:
I'm working in an Access XP database and I need to create a query which calculates what the date will be 6 business days after . I have no idea where to start and most posts I find on calculating...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.