waqas
waqas

Reputation: 181

Get Weeks start date when week start is different year and week end is different year

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

Answers (2)

M.Ali
M.Ali

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

T McKeown
T McKeown

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

Related Questions