Home >Database >Mysql Tutorial >How to query today's data in mysql

How to query today's data in mysql

王林
王林Original
2020-09-27 14:56:496059browse

Mysql method of querying today’s data: [SELECT * FROM `order` WHERE TO_DAYS(order_time) = TO_DAYS(NOW())].

How to query today's data in mysql

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn