– 当月最后一天
SELECT LAST_DAY(now());
– 当月第一天
SELECT concat(date_format(LAST_DAY(now()),‘%Y-%m-’),‘01’);
– 当前季度的第一天:
select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-3 month),‘%Y-%m-’),‘01’);
– 当前季度的最后一天:
select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-1 month);
– 今年第一天
SELECT DATE_SUB(CURDATE(),INTERVAL dayofyear(now())-1 DAY);
– 今年最后一天
SELECT concat(YEAR(now()),‘-12-31’);
– 上月的第一天:
SELECT concat(date_format(LAST_DAY(now() – interval 1 month),‘%Y-%m-’),‘01’);
– 上月的最后一天:
SELECT LAST_DAY(now() – interval 1 month);
– 上季度的第一天
select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-6 month),‘%Y-%m-’),‘01’);
– 上季度的最后一天
select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-4 month);
– 去年第一天
SELECT DATE_SUB(CURDATE() – interval 1 YEAR,INTERVAL dayofyear(now())-1 DAY);
– 去年最后一天
SELECT concat(YEAR(now()- interval 1 YEAR),‘-12-31’);