Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sql

sql-server

I'd like to find last weeks dates

SELECT *
FROM Table
Where [Date] Between '04-Jan-2016' AND '15-Jan-2016'

Every time I run my SQL Query it needs to display last week.

like image 827
PriceCheaperton Avatar asked Jan 11 '16 10:01

PriceCheaperton


2 Answers

---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)
like image 192
PriceCheaperton Avatar answered Oct 11 '22 19:10

PriceCheaperton


SELECT *
FROM Table
Where [Date] Between DATEADD(wk,DATEDIFF(wk,7,GETDATE()),0) 
AND DATEADD(wk,DATEDIFF(wk,7,GETDATE()),4)
like image 32
Sahi Avatar answered Oct 11 '22 19:10

Sahi