Hi i need to display date range from 2019 to 2023 and week name as per the date using any one please help me out.
How to get date range from 2019 to 2023
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Hi i need to display date range from 2019 to 2023 and week name as per the date using any one please help me out.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit MohantyRank #112 · 20K reputationPosted Jul 20, 2022, 12:41 AM EDT
Check the below query
DECLARE @MinDate DATE = '2019-01-01' DECLARE @MaxDate DATE = '2022-12-31' SELECT TOP (DATEDIFF(DAY, @MinDate, @MaxDate) + 1) [Date] = DATEADD(DAY, ROW_NUMBER() OVER(ORDER BY a.object_id) - 1, @MinDate), (DATEDIFF(WW, DATEDIFF(D, 0, DATEADD(M, DATEDIFF(M, 7, DATEADD(DAY, ROW_NUMBER() OVER(ORDER BY a.object_id) - 1, @MinDate)), 0)) / 7 * 7, DATEADD(D, -1, DATEADD(DAY, ROW_NUMBER() OVER(ORDER BY a.object_id) - 1, @MinDate))) + 1) AS WeekNo FROM sys.all_objects a CROSS JOIN sys.all_objects b