Avatar of Eric Harris
Eric Harris
 asked on

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.
Microsoft SQL Server

Avatar of undefined
Last Comment
Eric Harris

8/22/2022 - Mon
Aaron Tomosky

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
Eric Harris

ASKER
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
ASKER CERTIFIED SOLUTION
Aaron Tomosky

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Anthony Perkins

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Eric Harris

ASKER
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
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Eric Harris

ASKER
Thanks