x

calculate date excluding weekends and holidays

I need to figure the next available working date using the following formula: date+2. From the result, I need to exclude weekends and holidays and move on to the next available workday. I do have a calendar table built that has fields referencing whether or not it is a weekend or holday. I just don't know how to go about moving forward if the date+2 lands on either a weekend or a holiday.

Any help would be greatly appreciated.

more ▼

asked May 21, 2010 at 12:08 PM in Default

bviola gravatar image

bviola
33 2 3 4

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

without knowing the exact schema of your tables....

select min(date)
from calendar_table
where
 date >= @date+2
and isholiday <> 1
and isweekend <> 1

and in English, get the earliest date equal to or greater than date+2 where the weekend and holiday flags aren't set

more ▼

answered May 21, 2010 at 12:32 PM

Kev Riley gravatar image

Kev Riley ♦♦
52.8k 47 49 76

Thank you so much for the information. I have everything working perfectly now.
May 21, 2010 at 03:55 PM bviola
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x94

asked: May 21, 2010 at 12:08 PM

Seen: 1976 times

Last Updated: May 21, 2010 at 12:08 PM