473,394 Members | 1,752 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,394 software developers and data experts.

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 2825
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:5D**********************************@microsof t.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**@discussions.microsoft.comwrote in message
news:5D**********************************@microsof t.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**@discussions.microsoft.comwrote in message
news:89**********************************@microsof t.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 fdtmNextWorkingDay
(
@pstrISOCountryCode 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 trelPublicHoliday
WHERE sdtmDate = @pdtmStart
AND strISOCountryCode = @pstrISOCountryCode)
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**@discussions.microsoft.comwrote in message
news:89**********************************@microsof t.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 fdtmNextWorkingDay
(
@pstrISOCountryCode 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 trelPublicHoliday
WHERE sdtmDate = @pdtmStart
AND strISOCountryCode = @pstrISOCountryCode)
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
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...
0
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.. ...
29
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...
29
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...
13
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...
17
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...
1
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...
7
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...
1
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...
1
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...

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.