x
login about faq Site discussion (meta-askssc)

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 '10 at 12:08 PM in Default

bviola gravatar image

bviola
33 2 2 3

(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 '10 at 12:32 PM

Kev Riley gravatar image

Kev Riley ♦♦
46.1k 38 43 69

Thank you so much for the information. I have everything working perfectly now.

May 21 '10 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



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x84

asked: May 21 '10 at 12:08 PM

Seen: 1367 times

Last Updated: May 21 '10 at 12:08 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.