Home > Database > Mysql Tutorial > body text

How to query today's data in mysql

王林
Release: 2020-09-27 14:56:49
Original
6028 people have browsed it

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`)
)
Copy after login

Query the data of the current day (today)

SELECT  *  FROM  ` order `  WHERE  TO_DAYS(order_time) = TO_DAYS(NOW())
Copy after login

Query the data of yesterday

SELECT  *  FROM  ` order `  WHERE  TO_DAYS(NOW()) - TO_DAYS(order_time) = 1
Copy after login

Query the data of the current month (this month)

SELECT * FROM `order` WHERE DATE_FORMAT(order_time, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m')
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template