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.
Transact SQL Working days
-
- SilverLounger
- Posts: 2403
- Joined: 05 Feb 2010, 22:21
- Location: London ENGLAND
Transact SQL Working days
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
-
- 4StarLounger
- Posts: 482
- Joined: 24 Jan 2010, 15:02
- Location: Colorado, USA
Re: Transact SQL Working days
Take a look at this question on StackOverflow.com.
Wendell
You can't see the view if you don't climb the mountain!
You can't see the view if you don't climb the mountain!
-
- SilverLounger
- Posts: 2403
- Joined: 05 Feb 2010, 22:21
- Location: London ENGLAND
Re: Transact SQL Working days
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.
-
- Administrator
- Posts: 78549
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Transact SQL Working days
Try one of these:
SQL Server Forums - Calculate workdays from a date
SQL Server Function to add working days on to a date
SQL Server Forums - Calculate workdays from a date
SQL Server Function to add working days on to a date
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 482
- Joined: 24 Jan 2010, 15:02
- Location: Colorado, USA
Re: Transact SQL Working days
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).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.
Wendell
You can't see the view if you don't climb the mountain!
You can't see the view if you don't climb the mountain!
-
- Administrator
- Posts: 78549
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Transact SQL Working days
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.
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
Hans
-
- SilverLounger
- Posts: 2403
- Joined: 05 Feb 2010, 22:21
- Location: London ENGLAND
Re: Transact SQL Working days
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.