I am using SQL Server 2017 and I need to get the week ranges between 2 date ranges. I found a similar question week ranges But it will not work all scenarios
Code:
declare @sDate date='2020-04-24',
@eDate date='2020-05-07';
;with cte as
(
select @sDate StartDate,
DATEADD(wk, DATEDIFF(wk, 0, @sDate), 6) EndDate
union all
select dateadd(ww, 1, StartDate),
dateadd(ww, 1, EndDate)
from cte
where dateadd(ww, 1, StartDate)<= @eDate
)
select *
from cte
Expected output: (week first as Sunday)