June 3, 2011 at 3:17 am
Hi Guys,
I have written a view that consists of data from a table called Tasks. Basically each task has a start date, end date, estimated end date, estimated hours, actual hours complete.
Now I calculate the estimated end date like this:
I divide the number of estimated hours by 2. Then add the result to the Start Date using the DateAdd function.(my boss came up with that algorithm)
However, I need to determine which of the days between the Start Date and Estimated End Date are weekends. If there is a weekend I need to add two days more to the estimated end date.
Please help me achieve this.
June 3, 2011 at 4:35 am
You can use DATEPART to check the weekday:
select datepart(weekday , getdate())
Depending on your @@DATEFIRST setting, you will have to check for days 1 and 7 (default for US English) or 6 and 7 (default for Italian).
Hope this helps
Gianluca
-- Gianluca Sartori
June 3, 2011 at 5:04 pm
This expression is independent of any language and datefirst settings:
-- gives 1 for monday..., 7 for sunday
datepart( weekday, @datetime + @@datefirst - 1 )
June 6, 2011 at 1:20 am
Vedran Kesegic (6/3/2011)
This expression is independent of any language and datefirst settings:
-- gives 1 for monday..., 7 for sunday
datepart( weekday, @datetime + @@datefirst - 1 )
This is a really smart solution! Saved it in my code snippets. 🙂
Thanks a lot.
-- Gianluca Sartori
June 7, 2011 at 2:49 am
Hi,
There is no harm in usung this
select datename(dw,getdate())
and can check for Sat or Sun accordingly.
Regards
Ashok
June 7, 2011 at 2:56 am
ashok.faridabad1984 (6/7/2011)
Hi,There is no harm in usung this
select datename(dw,getdate())
and can check for Sat or Sun accordingly.
Regards
Ashok
It still depends on the client's language:
set language italian
select datename(dw,getdate())
Saturday is called "Sabato" here.
-- Gianluca Sartori
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply