Reputation: 181
Today is 30-12-2013 and in my sql server week is start from Sunday.Its mean week start 29-12-2013 and week end date is saturday 4-1-2014.
I want week start date using end date 4-1-2014.Is there any way to find week start date when date is two on different years.
I got the week start date and end date of week when years are same.But I want week start date when both years are different.
Upvotes: 0
Views: 85
Reputation: 69594
DECLARE @date DATE;
SET @date = '20140104';
SELECT DATEADD(dd, -(DATEPART(dw, @date)-1), @date) [Week Start],
DATEADD(dd, 7-(DATEPART(dw, @date)), @date) [WeekEnd]
Result
╔════════════╦════════════╗
║ Week Start ║ WeekEnd ║
╠════════════╬════════════╣
║ 2013-12-29 ║ 2014-01-04 ║
╚════════════╩════════════╝
Upvotes: 1
Reputation: 12857
JUST SUBTRACT DAYS TO END DATE, EXAMPLE:
SELECT GETDATE() - 7
ADDING (+/-) DAYS IS THE SAME IF YOU REPLACE GETDATE() WITH A DATETIME COLUMN OR @VARIABLE
Upvotes: 1