Today
SELECT * FROM table name where To_days (Time field name) = To_days (now ());
Yesterday
SELECT * FROM table name WHERE to_days (now ())-To_days (Time field name) <= 1
Nearly 7 days
SELECT * FROM table name where Date_sub (Curdate (), INTERVAL 7 day) <= Date (Time field name)
Nearly 30 days
SELECT * FROM table name where Date_sub (Curdate (), INTERVAL Day) <= Date (Time field name)
Month
SELECT * FROM table name WHERE date_format (Time field name, '%y%m ') = Date_format (Curdate (), '%y%m ')
Last month
SELECT * FROM table name WHERE Period_diff (Date_format (now (), '%y%m '), Date_format (Time field name, '%y%m ')) =1
Query this quarterly data
SELECT * from ' ht_invoice_information ' where QUARTER (create_date) =quarter (now ());
Query last quarter data
SELECT * from ' ht_invoice_information ' where QUARTER (create_date) =quarter (Date_sub (now (), Interval 1 QUARTER));
Query this year's data
SELECT * from ' Ht_invoice_information ' where year (create_date) =year (now ());
Query last year data
SELECT * from ' Ht_invoice_information ' where year (create_date) =year (Date_sub (now (), interval 1));
Querying data for the current week
SELECT Name,submittime from the Enterprise WHERE Yearweek (Date_format (submittime, '%y-%m-%d ')) = Yearweek (now ());
Query last week's data
SELECT Name,submittime from the Enterprise WHERE Yearweek (Date_format (submittime, '%y-%m-%d ')) = Yearweek (now ())-1;
Querying data for the previous month
SELECT * from user where pudate between last day of the month
Querying data for the current month
Select Name,submittime from Enterprise where Date_format (submittime, '%y-%m ') =date_format (now (), '%y-%m ')
Query data that is currently 6 months from now
Select Name,submittime from Enterprise where Submittime between Date_sub (now (), Interval 6 month) and now ();
MySQL Query day, this week, this month, the last one months of data