473,765 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 25993
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*@discussion s.microsoft.com wrote in message
news:E8******** *************** ***********@mic rosoft.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*@discussion s.microsoft.com wrote in message
news:E8******** *************** ***********@mic rosoft.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*@discussion s.microsoft.com wrote in message
news:E8******** *************** ***********@mic rosoft.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*@discussion s.microsoft.com wrote in message
news:E8******** *************** ***********@mic rosoft.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*@discussion s.microsoft.com wrote:
>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
23836
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 date and come up with a new date. Is that possible. Also, is there anyway that DB2 can be aware of holidays? Maybe load them onto the server in some type of reference file or something. I ask these questions because I'm working on a banking...
8
7520
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
2448
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) from that date. i have read some forums on getting total business day but not the other way around
2
8711
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 those or else is there any other option
17
15423
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
24553
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 business days count which is defined as count of days (optionally inclusive in the current implementation) excluding weekend days and holidays. Let us say periods to calculate are stored in table associated with contacts. keyPeriodID -...
0
9227
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 ( i_Date1 IN DATE, i_Date2 IN DATE ) RETURN NUMBER IS
1
2790
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 workingday of month. Can u please help me out with this as i am very new to oracle. Plzzzzzzz
3
9946
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 business days pertains to subtracting data in two date fields. I can build an expression in my query to add the date, Date_Due: + 5 but that doens't address the business days. Thanks in advance!
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7378
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.