Selecting MySQL Records with a Date Equal to Today
When working with a MySQL database, you may encounter the need to retrieve records based on a specific date, particularly when assessing data for the current day. This article provides a solution to accomplish this task.
To select records with a date column equal to today, where the data type is datetime, follow the steps below:
SELECT users.id, DATE_FORMAT(users.signup_date, '%Y-%m-%d') FROM users WHERE DATE(users.signup_date) = CURDATE()
This query selects the id and formatted signup date for users whose signup date matches today's date. If you wish to select only the id, you can modify the query as follows:
SELECT id FROM users WHERE DATE(signup_date) = CURDATE()
By implementing these steps, you can efficiently retrieve records that meet the specified date criteria from your MySQL database. This technique can be applied to any table containing a datetime or date column where you need to filter data based on today's date.
The above is the detailed content of How to Select MySQL Records with a Date Equal to Today?. For more information, please follow other related articles on the PHP Chinese website!