This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Check the below input date and expected output to find the last Sunday of the previous week in SQL Server.
Input Date: ‘2018-04-15’
Expected Output:
1 2 3 |
Last_Sunday ----------------------- 2018-04-08 00:00:00.000 |
Solution:
1 2 3 4 5 6 |
DECLARE @MyDate DATETIME = '2018-04-15' SELECT DATEADD(DAY, -1 - (DATEPART(weekday, @MyDate) + @@DATEFIRST - 2) % 7, @MyDate ) AS Last_Sunday |
Please try the different solution for this puzzle and share it via comment...