Description
The following code:
<?php
$period = new DatePeriod(
new DateTimeImmutable('2025-01-31'),
new DateInterval('P1M'),
new DateTimeImmutable('2025-04-30'),
);
foreach ($period as $date) {
echo $date->format('Y-m-d') . PHP_EOL;
}
Resulted in this output:
2025-01-31
2025-03-03
2025-04-03
But I expected this output instead:
2025-01-31
2025-02-28
2025-03-31
It seems PHP's having a hard time when the start month has more days than the next one.
Thanks!
PHP Version
PHP 8.3.16
Operating System
macOS 15.2