How to query data for today in MySQL

To query data from a table for the current day, you can use the following query code:

SELECT *
FROM table_name
WHERE DATE(date_field_name) = CURDATE()

where table_name =  the name of the table where you want to get data from.

date_field_name - name of the field where dates are stored (in date or datetime format)

 

An alternative is to write today's date into the query using PHP (sometimes it makes sense if you use indexing on a date column):

$mysqlQuery = "SELECT *
FROM table_name
WHERE date_field_name > '" . date('Y-m-d') . " 00:00:00' ";

Comments

No comments yet, you can leave yours: