Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Excluding weekends

Author  Topic 

hog
Constraint Violating Yak Guru

284 Posts

Posted - 2005-11-18 : 08:20:40
Is there a better way to calculate a future date that ignores weekends other that using datepart to test for the day?

Example:

Add 7 to 04/05/2006 results in 11/05/2006

But if the weekend is ignored you would get 12/05/2006

I can just add 8 instead as it could end up with the end date landing on a weekend.

I need to calculate working days only as we dont work weekends.

Thnx for any tips :)


madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-18 : 08:27:18
See if this helps you
http://weblogs.sqlteam.com/brettk/archive/2005/05/12/5139.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

hog
Constraint Violating Yak Guru

284 Posts

Posted - 2005-11-18 : 08:40:04
Thnx :)

I have tried this but get error Line 2: Incorrect syntax near '04/05/2006'

declare @T int
select @T = calculate_weekday '04/05/2006', '12/05/2006'
print @T

I have tried omitting the quotes, adding # etc.

DOH! how do you pass a date :(
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-18 : 08:49:35
Which function are you using?
Try this

declare @T int
select @T = dbo.calculate_weekday_function ('04/05/2006', '12/05/2006')
print @T


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

hog
Constraint Violating Yak Guru

284 Posts

Posted - 2005-11-18 : 08:56:39
I'm using the function code in the centre of the post you sent.

If I run this I get 6, have to use American date format tho! The six would suggest it does not include the first date? I make it as being 7?

declare @T int
select @T = dbo.calculate_weekday('05/04/2006', '05/12/2006')
print @T
Go to Top of Page
   

- Advertisement -