3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('UTC'); $today = new DateTime; //to be sure that DateInterval will work as intended //we take the first day of the month $fist_day_of_the_month = $today->format('Y-m-01'); $range = new DatePeriod( new DateTime($fist_day_of_the_month), //begin new DateInterval('P1M'), //interval new DateTime($fist_day_of_the_month.' +24 month') //end ); foreach ($range as $date) { echo $date->format('Y-m-d'), PHP_EOL; }

preferences:
40.24 ms | 402 KiB | 5 Q