nagarjuna nagarjuna - 5 months ago 6x
SQL Question

In sqlserver how to find last before week data?

I am trying the below query, but it's output comes last 2 weeks data, but I need only last before week data only.

My week starts from Friday. So I need all rows between Friday to Friday.

select * from tablename where createddate>=DATEADD(WEEK,-2, GETDATE()) ;


From one your comments I found that the week you are talking about starts from Friday, so you need to add up those gap days into your condition

SELECT * FROM tablename 
WHERE createddate >= DATEADD(ww, DATEDIFF(ww, 4 ,DATEADD(WEEK, -1, GETDATE())), 4)
AND createddate < DATEADD(ww, DATEDIFF(ww, 4 ,DATEADD(WEEK, 0, GETDATE())), 4)