Transact SQL Working days

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Transact SQL Working days

Post by agibsonsw »

Hello. SQL Server 2005.

I would like to create a user-defined function in Transaction SQL to add, for example, 45 working days to a date.
Does someone have code for this function already? Thanks, Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
Wendell
4StarLounger
Posts: 482
Joined: 24 Jan 2010, 15:02
Location: Colorado, USA

Re: Transact SQL Working days

Post by Wendell »

Take a look at this question on StackOverflow.com.
Wendell
You can't see the view if you don't climb the mountain!

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Transact SQL Working days

Post by agibsonsw »

Hello. I think that provides the number of days between dates. I want to add a number of working days to a date. Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
HansV
Administrator
Posts: 78549
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Transact SQL Working days

Post by HansV »

Best wishes,
Hans

User avatar
Wendell
4StarLounger
Posts: 482
Joined: 24 Jan 2010, 15:02
Location: Colorado, USA

Re: Transact SQL Working days

Post by Wendell »

agibsonsw wrote:Hello. I think that provides the number of days between dates. I want to add a number of working days to a date. Andy.
Sorry, but I believe you are wrong - the thread is clearly titled "Count work days between two dates in T-SQL" and the code does exactly that with precision varying depending on the post you choose to use. The links Hans provided do the same thing but with different approaches. It's amazing how many different ways you can do things in T-SQL and still have it work (and in many cases only make sense to the original author).
Wendell
You can't see the view if you don't climb the mountain!

User avatar
HansV
Administrator
Posts: 78549
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Transact SQL Working days

Post by HansV »

Hi Wendell,

They are not quite the same - the functions in your links calculate the difference between two dates, excluding weekend days. Andy wants to add a number of days to a date, excluding weekend days.
Best wishes,
Hans

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Transact SQL Working days

Post by agibsonsw »

Thank you, that's just what I was looking for. Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.