select curdate(); --获取当前日期
select last_day(curdate()); --获取当月最后一天。
select DATE_ADD(curdate(),interval -day(curdate())+1 day); --获取本月第一天
select date_add(curdate()-day(curdate())+1,interval 1 month); -- 获取下个月的第一天
select DATEDIFF(date_add(curdate()-day(curdate())+1,interval 1 month ),DATE_ADD(curdate(),interval -day(curdate())+1 day)) from dual; --获取当前月的天数
select * from 表名 where to_days(时间字段) = to_days(now());
select * from 表名 where to_days(now())-to_days(时间字段) = 1;
select * from 表名 where date_sub(curdate(), interval 7 day) <= date(时间字段);
select * from 表名 where 时间字段 between date_sub(now(),interval 6 month) and now();
select * from 表名 where yearweek(date_format(时间字段,'%Y-%m-%d')) = yearweek(now());
select * from 表名 where yearweek(date_format(时间字段,'%Y-%m-%d')) = yearweek(now())-1;
select * from 表名 where date_format(时间字段,'%Y-%m')=date_format(now(),'%Y-%m');
select * from 表名 where date_format(时间字段,'%Y-%m')=date_format(date_sub(curdate(), interval 1 month),'%Y-%m');