mysql 查询上个月某一天


本文地址:http://www.cnblogs.com/jying/p/8877065.html

需求:获取上个月15号的日期
网上一搜一大堆粘贴复制的大坑:(如下是查询上个月最后一天,可是我要的不一定是哪一天啊!!!坑)
select date_sub(date_sub(date_format(now(),'%y-%m-%d'),interval extract(day from now()) day),interval 0 month) as date; 希望: 最后找到一个函数 extract(year_month from date_add(now(), interval -1 month)); 然后搜索 extract 函数解释 ,date_add解释。 解决: select concat(date_format(date_add(now(),interval -1 month),'%Y-%m'),'-15') d2222; 延伸(与上面结果一样): select concat(date_format(date_sub(now(),interval 1 month),'%Y-%m'),'-15') d1111;

 
本文地址:http://www.cnblogs.com/jying/p/8877065.html

原文地址:https://www.cnblogs.com/jying/p/8877065.html