$dateStart = new \DateTime(); //開始日期
$dateInterval = \DateInterval::createFromDateString('+1 month'); //間隔設定 例如 +1 day 或 -1 month
$datePeriod = new \DatePeriod($dateStart, $dateInterval, 24); //要作幾次
foreach ($datePeriod as $v) {
echo $v->format('Y-m-d');
echo '<br>';
}
顯示結果如下:
2015-10-01
2015-11-01
2015-12-01
2016-01-01
2016-02-01
2016-03-01
2016-04-01
2016-05-01
2016-06-01
2016-07-01
2016-08-01
2016-09-01
2016-10-01
2016-11-01
2016-12-01
2017-01-01
2017-02-01
2017-03-01
2017-04-01
2017-05-01
2017-06-01
2017-07-01
2017-08-01
2017-09-01
2017-10-01
2015-11-01
2015-12-01
2016-01-01
2016-02-01
2016-03-01
2016-04-01
2016-05-01
2016-06-01
2016-07-01
2016-08-01
2016-09-01
2016-10-01
2016-11-01
2016-12-01
2017-01-01
2017-02-01
2017-03-01
2017-04-01
2017-05-01
2017-06-01
2017-07-01
2017-08-01
2017-09-01
2017-10-01
No comments:
Post a Comment