From: http://www.myexception.cn/mysql/485349.html
Use of MySQL time functions: query data of this week, last week, this month, and last 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 );
/* Query data 6 months from the current time */
Select * from table name where time field between date_sub (now (), interval 6 month) and now ();
/* Query the data for the current week */
Select * from table name where yearweek (date_format (time field, '% Y-% m-% D') = yearweek (now ());
/* Query last week's data */
Select * from table name where yearweek (date_format (time field, '% Y-% m-% D') = yearweek (now ()-1;
/* Query the data of the current month */
Select * from table name where date_format (time field, '% Y-% m') = date_format (now (),' % Y-% m ');
/* Query the data of the previous month */
Select * from table name where date_format (time field, '% Y-% m') = date_format (date_sub (curdate (), interval 1 month ), '% Y-% m ');