$d1 = '2015-08-30';
echo date('m', strtotime('+1 month', strtotime($d1))); //會印出 09
重點來了,如果是大月的最後一天,就會印出不一樣的結果
$d2 = '2015-08-31';
echo date('m', strtotime('+1 month', strtotime($d2))); //會印出 10
解法是:
$d2 = '2015-08-31';
echo date('m', strtotime('first day of +1 month', strtotime($d2))); //會印出 09
PS.上個月就用 -1 month
No comments:
Post a Comment