Home >Database >Mysql Tutorial >How to Select Records for a Specific Week in MySQL: Monday to Sunday or Sunday to Saturday?
MySQL: Selecting Records for a Week
Initial Problem:
How to retrieve records from a table for a specific week, given a specified date?
Traditional Algorithm:
Shorter Algorithm (Using MySQL's YEARWEEK() Function):
SELECT * FROM your_table WHERE YEARWEEK(`date`, 1) = YEARWEEK(CURDATE(), 1)
Explanation:
Addressing the Additional Question:
The provided query used by the user selects records for the week from Sunday to Saturday, instead of Monday to Sunday. To correct this, the following modification can be made:
SELECT * FROM your_table WHERE YEARWEEK(`date`, 3) = YEARWEEK(CURDATE(), 3)
The above is the detailed content of How to Select Records for a Specific Week in MySQL: Monday to Sunday or Sunday to Saturday?. For more information, please follow other related articles on the PHP Chinese website!