PHP 计算两个日期相差月份

方法整理自:https://stackoverflow.com/questions/18742998/how-to-list-all-months-between-two-dates

修改后的代码如下:

$arr = array();
$start = new DateTime('2017-09-02');
$start->modify('first day of this month');
$end = new DateTime(gmdate("Y-m-d", time()+8 * 3600));
$end->modify('first day of next month');
$interval = DateInterval::createFromDateString('1 month');
$period = new DatePeriod($start, $interval, $end);
foreach ($period as $dt) {
$arr['date'][] = $dt->format("Ym");
}

未经允许不得转载:阿藏博客 » PHP 计算两个日期相差月份

赞 (0) 打赏