当天:where to_days(时间字段名)= to_days(now());
本周:where YEARWEEK(date_format(时间字段,'%Y-%m-%d')) = YEARWEEK(now());
最近七天:where date_sub(curdate(), INTERVAL 7 DAY) <= date (时间字段);
本月:where date_format(时间字段, '%Y%m') = date_format(curdate() , '%Y%m');
最近三十天:where date_sub(curdate(), INTERVAL 30 DAY) <= date(时间字段);
上个月:WHERE PERIOD_DIFF( date_format( now( ) ,'%Y%m' ) , date_format( 时间字段名,'%Y%m' ) )=1
本季度:WHERE QUARTER(create_date)=QUARTER(now());
上季度:where QUARTER(DATE_SUB(now(),interval1 QUARTER));
本年:where YEAR(create_date)=YEAR(NOW());
上年:where year(create_date)=year(date_sub(now(),interval1year));
上周:where YEARWEEK(date_format(submittime,'%Y-%m-%d'))= YEARWEEK(now())-1;
网友评论