473,289 Members | 1,829 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,289 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 25935
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...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.