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

avatar image

bviola
33 3 4 6

(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

avatar image

Kev Riley ♦♦
63.8k 48 61 81

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.

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:

x80

asked: May 21, 2010 at 12:08 PM

Seen: 2267 times

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

Copyright 2016 Redgate Software. Privacy Policy