MySQL queries the SQL code for the data of this week, last week, this month, and last month.
Http://www.jb51.net/article/32277.htm
There are many ways to query MySQL. The MySQL query Implementation described below is to query data from this week, last week, this month, and last month. If you are interested in MySQL query, take a look
Query data for the current weekSELECT name, submittime FROM enterprise where yearweek (date_format (submittime, '% Y-% m-% D') = YEARWEEK (now ());
Query last week's data
SELECT name, submittime FROM enterprise where yearweek (date_format (submittime, '% Y-% m-% D') = YEARWEEK (now ()-1;
Query data of the current month
Select name, submittime from enterprise where date_format (submittime, '% Y-% m') = date_format (now (),' % Y-% m ')
Query data 6 months from the current time
Select name, submittime from enterprise where submittime between date_sub (now (), interval 6 month) and now ();
Query data of last month
Select name, submittime from enterprise where date_format (submittime, '% Y-% m') = date_format (DATE_SUB (curdate (), INTERVAL 1 MONTH ), '% Y-% m ')
Select * from 'user' where DATE_FORMAT (pudate, '% Y % m') = DATE_FORMAT (CURDATE (),' % Y % m ');
Select * from user where WEEKOFYEAR (FROM_UNIXTIME (pudate, '% y-% m-% D') = WEEKOFYEAR (now ())
Select *
From user
Where MONTH (FROM_UNIXTIME (pudate, '% y-% m-% D') = MONTH (now ())
Select *
From [user]
Where YEAR (FROM_UNIXTIME (pudate, '% y-% m-% D') = YEAR (now ())
And MONTH (FROM_UNIXTIME (pudate, '% y-% m-% D') = MONTH (now ())
Select *
From [user]
Where pudate between last day of last month
And the first day of next month
Today
Select * from table name where to_days (time field) = to_days (now ());
Yesterday
Select * from table name where to_days (now ()-to_days (time field) = 1;
Last 7 days
Select * from table name where date_sub (curdate (), interval 7 day) <= date (time field );
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.