Get All Rows For the Current Week (Sunday to Saturday)

I recently had a project where I needed to display all the rows from a mySQL database where the a date field occurred in the current week (From Sunday to Saturday).  To keep from building out a complete query in php, I went with a little less complex query all in the SQL query.


SELECT * FROM table
WHERE
rec_date >= curdate() - INTERVAL DAYOFWEEK(curdate()) - 1 DAY
AND rec_date <= curdate() - INTERVAL DAYOFWEEK(curdate()) - 7 DAY

Using the curdate function and the DAYOFWEEK function we can calculate the number of days to subtract from the current date to get our starting and ending date ranges to select from.

Scroll to Top