Home > Database > Mysql Tutorial > body text

How to query data within 30 days in mysql

王林
Release: 2020-09-29 14:36:52
Original
7249 people have browsed it

Mysql method to query data within 30 days: execute the sql statement [SELECT * FROM table name where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date (time field name);].

How to query data within 30 days in mysql

Today:

(Recommended tutorial: mysql tutorial)

SELECT * FROM 表名 WHERE TO_DAYS( 时间字段名) = TO_DAYS(NOW());
Copy after login

Yesterday:

SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ) - TO_DAYS( 时间字段名) <= 1;
Copy after login

7 days ago:

SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(时间字段名);
Copy after login

30 days:

SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(时间字段名);
Copy after login

This month:

SELECT * FROM 表名 WHERE DATE_FORMAT( 时间字段名, &#39;%Y%m&#39; ) = DATE_FORMAT( CURDATE( ) , &#39;%Y%m&#39; );
Copy after login

Related recommendations: php training

The above is the detailed content of How to query data within 30 days 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