I want to input a date and have it return the Monday of that week, but at my company the week starts on Monday and ends on Sunday. I tried using SET DATEFIRST 1 to make Monday the first day of the week, but this didn't help me with Sundays.
code:
DECLARE @proddate datetime = '6/12/2016'
SET DATEFIRST 1; SELECT DATEADD(wk, DATEDIFF(wk,0,@proddate), 0) MondayOfWeek
returns:
6/9/2016 -> 6/6/2016
6/12/2016 -> 6/13/2016 (should be 6/6/2016)
Try this:
SELECT DATEADD(DAY, 1-DATEPART(WEEKDAY, @proddate), @proddate)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With