Easy:
--start of last week
SELECT DATEADD(wk, DATEDIFF(wk, 6, GETDATE()), 0)
--end of last week
SELECT DATEADD(wk, DATEDIFF(wk, 6, GETDATE()), 6)
EDIT:
The below will handle the Sunday date issue.
DECLARE @input varchar(10)
--SET @input = '9/9/2012' -- simulates a Sunday
SET @input = GETDATE()
--start of last week
SELECT DATEADD(wk, DATEDIFF(wk, 6,
CASE DATEPART(dw,@input)
WHEN 1 THEN DATEADD(d,-1,@input)
ELSE @input
END
), 0)
--end of last week
SELECT DATEADD(wk, DATEDIFF(wk, 6,
CASE DATEPART(dw,@input)
WHEN 1 THEN DATEADD(d,-1,@input)
ELSE @input
END
), 6)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…