3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start = (new DateTime(date('Y-m-d')))->modify('first day of this month'); $end = (new DateTime(date('Y-m-d', strtotime('-1 years'))))->modify('first day of this month'); $interval = DateInterval::createFromDateString('1 month'); $period = new DatePeriod($start, $interval, $end); die(var_dump($period)); foreach ($period as $dt) { die(var_dump($dt->format("Y-m"))); }

preferences:
47.69 ms | 402 KiB | 5 Q