I already find to get the week number but, that shows the date in different way.
Actually When I check the week number for the Date of
select datepart(wk,'2016-01-02') //Saturday
output: 1
select datepart(wk,'2016-01-03') //Sunday
output: 2
But when I get the date of starting and ending date of weeks using week number, It shows different.
DECLARE @weekStart INT
DECLARE @weekEnd INT
DECLARE @Year INT
set @weekStart = 1
set @Year = 2016
DECLARE @WeekStartDate date
DECLARE @WeekEndDate date
SET @WeekStartDate = convert(date,DATEADD (WEEK, @weekStart, DATEADD (YEAR, @Year-1900, 0)) - 4 -
DATEPART(DW, DATEADD (WEEK, @weekStart, DATEADD (YEAR, @Year-1900, 0)) - 4) + 1)
SET @WeekEndDate =convert(date,DATEADD (WEEK, @weekStart+1, DATEADD (YEAR, @Year-1900, 0)) - 4 -
DATEPART(DW, DATEADD (WEEK, @weekStart+1, DATEADD (YEAR, @Year-1900, 0)) - 4) + 1)
select @WeekStartDate,@WeekEndDate
output:
StartingDate EndingDate
--------------------------
2016-01-03 2016-01-09
I am expecting output is, if I give week = 1 it should give StartingDate = **
2016-01-01
and **EndingDate =2016-01-02
for the week number 2, it should give
2016-01-03 2016-01-09