Sql add days to a date taking into account the weekend

Hi,

I'm trying to calculate a due date for an order based on a set lead days parameter.
Ideally 'd like to do this in a function.

I have an order creation date.
From that I want to add 5 working days to it.
However, if part or all of the weekend fall within the 5 days I want to be able to take that into account

So an order placed on Thursday would be due the follwing Thursday.
i.e 5 working days plus 2 non working days.

Can anyone help me with the syntax.
Eric HarrisDeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aaron TomoskySD-WAN SimplifiedCommented:
This has been discusse many times. Ere is a decent article
http://stackoverflow.com/questions/252519/count-work-days-between-two-dates-in-t-sql
0
Eric HarrisDeveloperAuthor Commented:
THanks for that.
It does calculate the number of working days between 2 dates.

However, I'd like to be able to add 5 working days to the startdate.
So I need to calculate the end date
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Anthony PerkinsCommented:
You don't need a UDF for this.  All you need is to build a "Workdays" table from here to a reasonable number of years in the future, than your query becomes a trivial calculation.  The big advantage of this approach is that you can also now expand to include Holidays as well.  Let me know if you are interested.
0
Eric HarrisDeveloperAuthor Commented:
All a big help
I did actually get round to using a udf to do it.
Seems to work a treat

I'm pleased to say it's not that differnt from the solution posted by aarontomosky.

Thanks Everyone
0
Eric HarrisDeveloperAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.