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) { $dt->format("Y-m"); }

preferences:
31.84 ms | 402 KiB | 5 Q