Http://www.jb51.net/article/32277.htm
MySQL query a lot of ways, the following for you to introduce the MySQL query is to query this week, last week, this month, the last month's data, if you are interested in MySQL query, may wish to see/ * 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;
/* Nearly 7 days */
select * FROM table name where Date_sub (Curdate (), Interval 7 day) <= Date (Time field);
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 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 ();
querying data for the previous 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 the last day of last month
And the first day of next month
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MySQL Query SQL code for this week, last week, this month, and last month's data