php日付計算月初月末
//2ヶ月前
$stdate[]=date('Y-m-d', strtotime(date('Y-m-1').' -2 month'));
$monthw[]=date('Y-m', strtotime(date('Y-m-01') . '-2 month'));
$endate[]=date('Y-m-d', strtotime(date('Y-m-1').' -1 month -1 day'));
//1ヶ月前
$stdate[]=date('Y-m-d', strtotime(date('Y-m-01') . '-1 month'));
$monthw[]=date('Y-m', strtotime(date('Y-m-01') . '-1 month'));
$endate[]=date('Y-m-d', strtotime(date('Y-m-1').' 0 month -1 day'));
//等月
$stdate[]=date("Y-m-01", time());
$monthw[]=date("Y-m", time());
$endate[]=date("Y-m-t", time());
//1ヶ月後
$stdate[]=date('Y-m-d', strtotime(date('Y-m-01') . '+1 month'));
$monthw[]=date('Y-m', strtotime(date('Y-m-01') . '+1 month'));
$endate[]=date('Y-m-d', strtotime(date('Y-m-1').' +2 month -1 day'));
//2ヶ月後
$stdate[]=date("Y-m-01",strtotime("+2 month"));
$monthw[]=date('Y-m', strtotime(date('Y-m-01') . '+2 month'));
$endate[]=date('Y-m-d', strtotime(date('Y-m-1').' +3 month -1 day'));
print_r($stdate);
print_r($endate);
print_r($monthw);
Array
(
[0] => 2016-08-01
[1] => 2016-09-01
[2] => 2016-10-01
[3] => 2016-11-01
[4] => 2016-12-01
)
Array
(
[0] => 2016-08-31
[1] => 2016-09-30
[2] => 2016-10-31
[3] => 2016-11-30
[4] => 2016-12-31
)
Array
(
[0] => 2016-08
[1] => 2016-09
[2] => 2016-10
[3] => 2016-11
[4] => 2016-12
)

????