display series of month in php between years

$start    = (new DateTime(‘2025-01-01’))->modify(‘first day of this month’);

$end      = (new DateTime(‘2036-01-01’))->modify(‘first day of next month’);

$interval = DateInterval::createFromDateString(‘1 month’);

$period   = new DatePeriod($start, $interval, $end);

foreach ($period as $dt) {

    echo $dt->format(“Y-m”) . “<br>\n”;

}




Leave a Reply