今日
SELECT * FROM table_name WHERE to_days(createtime) = to_days(now());
本周
SELECT * FROM table_name WHERE YEARWEEK(date_format(createtime,'%Y-%m-%d')- INTERVAL 1 DAY) = YEARWEEK(now());
提示:歪国人一周开始是从周日开始算起的,这里按照国人的习惯从周一算起,所以在记录日期基础上-1天。
本月
SELECT * FROM table_name WHERE date_format(createtime,'%Y-%m')=date_format(now(),'%Y-%m')