1. Today
SELECT * from table WHERE TO_DAYS (time field name) = TO_DAYS (now ());
2. Yesterday
The SELECT * the FROM table name the WHERE TO_DAYS (the NOW ()) - TO_DAYS (Time field) <= 1
3. The last seven days
The SELECT * the FROM table name WHERE for DATE_SUB (CURDATE (), the INTERVAL . 7 DAY ) <= DATE (Time field)
4. month
The SELECT * the FROM table name the WHERE the DATE_FORMAT (Time field name, ' %% the Y m ' ) = the DATE_FORMAT (CURDATE (), ' % m% the Y ' )
5. Kozuki
The SELECT * the FROM table name the WHERE PERIOD_DIFF (DATE_FORMAT (now (), ' %% the Y m ' ), DATE_FORMAT (Time field name, ' %% the Y m ' )) = . 1
6. This quarter
SELECT * from `table` WHERE QUARTER (Time field) = QUARTER (now ());
7. quarter
SELECT * from `table` WHERE QUARTER (Time field) = QUARTER (for DATE_SUB (now (), interval The . 1 QUARTER));
8. year
SELECT * from `table` WHERE YEAR (Time field) = YEAR (the NOW ());
9. Last year,
SELECT * from `table` WHERE year (time field) = year (DATE_SUB (now (), interval The . 1 year ));
10 this week
select * from table the WHERE yearWeek (DATE_FORMAT (time field, ' % Y-M-% D% ' )) = yearWeek (now ());
11. Last week,
select * from 表名 WHERE YEARWEEK(date_format(字段名,'%Y-%m-%d')) = YEARWEEK(now())-1;
12. the last 6 months
select * from 表名 where 字段名 between date_sub(now(),interval 6 month) and now();