Home >Database >Mysql Tutorial >How to query today's data in mysql
Mysql method of querying today’s data: [SELECT * FROM `order` WHERE TO_DAYS(order_time) = TO_DAYS(NOW())].
Create a table:
(Recommended tutorial: mysql video tutorial)
CREATE TABLE ` order ` ( `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `order_name` VARCHAR (45) NOT NULL , `order_time` DATETIME NOT NULL , PRIMARY KEY (`id`) )
Query the data of the current day (today)
SELECT * FROM ` order ` WHERE TO_DAYS(order_time) = TO_DAYS(NOW())
Query the data of yesterday
SELECT * FROM ` order ` WHERE TO_DAYS(NOW()) - TO_DAYS(order_time) = 1
Query the data of the current month (this month)
SELECT * FROM `order` WHERE DATE_FORMAT(order_time, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m')
Related recommendations: php training
The above is the detailed content of How to query today's data in mysql. For more information, please follow other related articles on the PHP Chinese website!