How do I find last weeks dates Monday to Friday using SQL Server? How do I find last weeks dates Monday to Friday using SQL Server? sql sql

How do I find last weeks dates Monday to Friday using SQL Server?


---To get the first day of the previous week in SQL Server, use the following code:

SELECT DATEADD(wk,DATEDIFF(wk,7,GETDATE()),0)

--To get the last day of the previous week:

SELECT DATEADD(wk,DATEDIFF(wk,7,GETDATE()),4)


Hopefully following is what you want,

--START OF LAST WEEK    SELECT DATEADD(wk, DATEDIFF(wk, 6, GETDATE()), 0)--END OF LAST WEEK    SELECT DATEADD(wk, DATEDIFF(wk, 6, GETDATE()), 4)DECLARE @input varchar(10)--SET @input = '01/10/2016' 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 @inputEND), 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), 4)


SELECT *FROM TableWhere [Date] Between DATEADD(wk,DATEDIFF(wk,7,GETDATE()),0) AND DATEADD(wk,DATEDIFF(wk,7,GETDATE()),4)