- ini_set: documentation ( source)
- error_reporting: documentation ( source)
- min: documentation ( source)
- printf: documentation ( source)
<?php
declare(strict_types=1);
error_reporting(-1);
ini_set('display_errors', 'On');
/**
* @param DateTimeImmutable $start
* @param DateTimeImmutable $end
*
* @return Generator
*/
function remainingDaysPerMonthBetween(\DateTimeImmutable $start, \DateTimeImmutable $end): \Generator {
while ($start < $end) {
$diff = $start->diff(min(
$start->modify('last day of this month'),
$end
));
yield [$start, $diff->days];
$start = $start->modify('first day of next month');
}
}
$start = new \DateTimeImmutable('2019-02-11');
$end = new \DateTimeImmutable('2019-04-23');
foreach (remainingDaysPerMonthBetween($start, $end) as [$date, $remainingDays]) {
printf("%s: %d\n", $date->format('M'), $remainingDays + 1);
}