473,769 Members | 3,872 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding days to start date

Hi, I have a web application that I need to add 3 days to the Now day, but
need to make sure that I skip weekends and holidays. For example if Now is
friday, 3 days + now should be tuesday, counting the current day as the first
day. Now would never occure on a weekend or holiday. Anyhow just wondering
if anyone has any ideas? Thanks.
--
Paul G
Software engineer.
Mar 20 '08 #1
4 2846
"Paul" <Pa**@discussio ns.microsoft.co mwrote in message
news:5D******** *************** ***********@mic rosoft.com...
Hi, I have a web application that I need to add 3 days to the Now day, but
need to make sure that I skip weekends and holidays. For example if Now
is
friday, 3 days + now should be tuesday, counting the current day as the
first
day. Now would never occur on a weekend or holiday. Anyhow just
wondering
if anyone has any ideas? Thanks.
It's a trivial matter to work out whether a DateTime variable relates to a
weekend or not by inspecting the DayOfWeek property:
http://msdn2.microsoft.com/en-us/lib...dayofweek.aspx

However, bear in mind that weekends are not always Saturday and Sunday
everywhere in the world.

As for public holidays, these differ from country to country. I'm not aware
of anything in the .NET Framework which will return whether given DateTime
and CultureInfo variables relate to a public holiday or not, although
Microsoft already know this information since it's possible to add public
holidays for individual countries to Outlook...

Therefore, what I do is hold a database table listing public holidays for
the next few years against a given country identifier. Armed with that, what
you require is easy enough by adding one day to any given DateTime variable
and incrementing a local variable by one if the resulting DateTime isn't a
weekend and doesn't appear in the database table of public holidays for the
country that you're working with. As soon as the local variable has a value
of 3, you have your result.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Mar 20 '08 #2
Hi thanks for the detailed information. I only have to worry about holidays
and weekends in the US so this does simplify it. Sounds like I may need to
store holiday dates in a table as you did.
Thanks Paul.
--
Paul G
Software engineer.
"Mark Rae [MVP]" wrote:
"Paul" <Pa**@discussio ns.microsoft.co mwrote in message
news:5D******** *************** ***********@mic rosoft.com...
Hi, I have a web application that I need to add 3 days to the Now day, but
need to make sure that I skip weekends and holidays. For example if Now
is
friday, 3 days + now should be tuesday, counting the current day as the
first
day. Now would never occur on a weekend or holiday. Anyhow just
wondering
if anyone has any ideas? Thanks.

It's a trivial matter to work out whether a DateTime variable relates to a
weekend or not by inspecting the DayOfWeek property:
http://msdn2.microsoft.com/en-us/lib...dayofweek.aspx

However, bear in mind that weekends are not always Saturday and Sunday
everywhere in the world.

As for public holidays, these differ from country to country. I'm not aware
of anything in the .NET Framework which will return whether given DateTime
and CultureInfo variables relate to a public holiday or not, although
Microsoft already know this information since it's possible to add public
holidays for individual countries to Outlook...

Therefore, what I do is hold a database table listing public holidays for
the next few years against a given country identifier. Armed with that, what
you require is easy enough by adding one day to any given DateTime variable
and incrementing a local variable by one if the resulting DateTime isn't a
weekend and doesn't appear in the database table of public holidays for the
country that you're working with. As soon as the local variable has a value
of 3, you have your result.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Mar 20 '08 #3
"Paul" <Pa**@discussio ns.microsoft.co mwrote in message
news:89******** *************** ***********@mic rosoft.com...
Hi thanks for the detailed information. I only have to worry about
holidays
and weekends in the US so this does simplify it. Sounds like I may need
to
store holiday dates in a table as you did.
If it helps, this is my SQL Server function for returning the next working
day, given a country code and a starting day

CREATE FUNCTION fdtmNextWorking Day
(
@pstrISOCountry Code char(2),
@pdtmStart smalldatetime
)
RETURNS smalldatetime
AS
BEGIN
DECLARE @blnWorkingDay bit
SET @blnWorkingDay = 0
WHILE @blnWorkingDay = 0
BEGIN
SET @pdtmStart = DATEADD(dd, 1, @pdtmStart)
IF (DATEPART(dw, @pdtmStart) BETWEEN 2 AND 6)
AND NOT EXISTS(SELECT * FROM trelPublicHolid ay
WHERE sdtmDate = @pdtmStart
AND strISOCountryCo de = @pstrISOCountry Code)
BEGIN
SET @blnWorkingDay = 1
END
END
RETURN @pdtmStart
END
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Mar 20 '08 #4
Hi thanks for the additional information. I was just wondering if there is a
source on the web that shows all of the holidays for the next 10 years,
including holidays that might show up on a weekend in one year and a weekday
on another year.
--
Paul G
Software engineer.
"Mark Rae [MVP]" wrote:
"Paul" <Pa**@discussio ns.microsoft.co mwrote in message
news:89******** *************** ***********@mic rosoft.com...
Hi thanks for the detailed information. I only have to worry about
holidays
and weekends in the US so this does simplify it. Sounds like I may need
to
store holiday dates in a table as you did.

If it helps, this is my SQL Server function for returning the next working
day, given a country code and a starting day

CREATE FUNCTION fdtmNextWorking Day
(
@pstrISOCountry Code char(2),
@pdtmStart smalldatetime
)
RETURNS smalldatetime
AS
BEGIN
DECLARE @blnWorkingDay bit
SET @blnWorkingDay = 0
WHILE @blnWorkingDay = 0
BEGIN
SET @pdtmStart = DATEADD(dd, 1, @pdtmStart)
IF (DATEPART(dw, @pdtmStart) BETWEEN 2 AND 6)
AND NOT EXISTS(SELECT * FROM trelPublicHolid ay
WHERE sdtmDate = @pdtmStart
AND strISOCountryCo de = @pstrISOCountry Code)
BEGIN
SET @blnWorkingDay = 1
END
END
RETURN @pdtmStart
END
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Mar 20 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1656
by: PK9 | last post by:
I have a loop where I need to calculate a series of dates based on: 1) a start date (DateTime variable) 2) a number of days (integer variable) I need to take the start date, then add the number of days to it, and come up with the next date. eg. - DateTime variable might equal 01/02/2005 - My integer for "Number of Days" is 10
0
1924
by: Chris Millar | last post by:
I have a user control that i wish to extend to change the date when the user selects the numeric up down button. The code explains itself, hope someone can help. any ideas appreaciated.. Chris. code :
29
9128
by: james | last post by:
I have a problem that at first glance seems not that hard to figure out. But, so far, the answer has escaped me. I have an old database file that has the date(s) stored in it as number of days. An example is: 36,525 represents 01/01/1900. The starting point date is considered to be : 00/00/0000. I have looked thru Help and used Google and have not really found an answer. I know that Leap Years need to be accounted for too. Any...
29
3231
by: Santiagoa | last post by:
If I set up a task table with an Date_assigned and a number of days to complete the task I calculate the end_date field by using the code below I found in this forum How ever when I enter the Date_assigned and update the record, nothing happens until I manually enter a value in the DaysToComplete field. I want to keep DaysToComplete Constant (5 Days) so I tried to set the attribute in the table with 5 as the default but this does not work....
13
2421
by: drago | last post by:
Hi guys, good to be here... I am struggling to calculated days in invoice system...Ok...The dates fields are of two kinds...One is the invoice start date and end date... The other one is the contract start date and end date...I have to calculate days of charging according to the dates involved... Suppose INVOICE start date: 01-01-07; INVOICE end date: 31-01-07 Conditions are: 1. IF the contract start date is BEFORE(<=) the invoice...
17
3448
by: ginajohnst | last post by:
Hi All. I'm having a problem adding days to a date. My date is in the string format dd/mm/yyyy eg. 23/08/2007 in my form field. I can't work out how to add 50 days to that date and then write it to another form field.
1
2809
by: Del | last post by:
I have a parameter query that requires the user to enter a Start Date: and End Date: and pull data between that date range. I am currently using the following parameter; Select * From mytable Where between and This query will always be run on a Monday and the start date will always be the previous Sunday. The end date will be the previous
7
3223
by: Mike | last post by:
I have a routine that's calculating business days but its not counting the weekend days that are between the start date and end date. If my start date is 9/26/08 and my end date is 10/01/08, I should see 4 business days and 2 weekend days. How can I get that result? I'm getting 4 business days but its not counting the weekend days?
1
4908
by: swethak | last post by:
Hi, I am desiging the calendar application for that purpose i used the below code. But it is for only displys calendar. And also i want to add the events to calendar. In that code displys the events when click on that date that perticular event displyed in a text box.But my requirement is to when click on that date that related event displyed in same td row not the text box. and also i add the events to that calendar.plz advice how to...
1
1082
by: printline | last post by:
Hi' All I have an ordering formular where users can choose on how many working days they want thier order on. I skip saturday and sunday because they are not working days and this works fine. If they place thier order after 3 o'clock in the afternoon an extra working day should be added. This also works fine in my script, but then the problem occurs. Instead of skipping staurday and sunday when they place their order after 3 o'clock, it...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
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
10206
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
10035
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
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6662
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();...
1
3949
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
3
2811
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.