Technical Article

First day and last day of a week

,

example

exec usp_first_day_and_last_day_of_week 2015,42

result

week        first day                                              last day                                               
----------- ------------------------------------------------------ ------------------------------------------------------ 
42          2015-10-12 00:00:00.000                                2015-10-18 00:00:00.000
(1 ligne(s) affectée(s))
create procedure usp_first_day_and_last_day_of_week(@y as int,@w as int)
as begin
--Kamel Gazzah 12/10/2015
--kamelgazzah@gmail.com
declare @fd as datetime
set @fd='01/01/'+convert(varchar(4),@y)
select @w "week",dateadd(day,8+7*(@w-2)-datepart(weekday,@fd),@fd)"first day",dateadd(day,14+7*(@w-2)-datepart(weekday,@fd),@fd)"last day"
end

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating