djt
djt

Reputation: 7535

MySQL Select Dates within Calendar week

I want to select all data from a table where a last_update field is 'this week'. So between the previous Sunday, and the upcoming Saturday.

I found this answer that finds dates LAST Week, but I can't quite figure out how to tailor it for what I need, which is this calendar week.

SELECT * FROM items
WHERE last_update >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
AND last_update < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY

Upvotes: 0

Views: 1330

Answers (1)

djt
djt

Reputation: 7535

I think I found the answer on this one:

SELECT * FROM items
WHERE last_update >= curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY
AND last_update <= curdate() + INTERVAL 7 DAY - DAYOFWEEK(curdate())

Upvotes: 3

Related Questions