作者:贞娜gina88 | 来源:互联网 | 2020-10-02 14:50
mysql查询今天的数据的方法:【SELECT * FROM `order` WHERE TO_DAYS(order_time) = TO_DAYS(NOW())】。
建表:
(推荐教程:mysql视频教程)
CREATE TABLE ` order ` (
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`order_name` VARCHAR (45) NOT NULL ,
`order_time` DATETIME NOT NULL ,
PRIMARY KEY (`id`)
)
查询当天(今天)的数据
SELECT * FROM ` order ` WHERE TO_DAYS(order_time) = TO_DAYS(NOW())
查询昨天的数据
SELECT * FROM ` order ` WHERE TO_DAYS(NOW()) - TO_DAYS(order_time) = 1
查询当月(本月)的数据
SELECT * FROM `order` WHERE DATE_FORMAT(order_time, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m')