本文位址: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