mysql怎么查询今天的数据

  • 来源:网络
  • 更新日期:2020-09-27

摘要:mysql查询今天的数据的方法:【SELECT * FROM `order` WHERE TO_DAYS(order_time) = TO_DAYS(NOW())】。建表:(推荐教程:mysql视频教程)CREATE TABLE ` order ` ( `id` INTE

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')

相关推荐:php培训