Petla do dniach miedzy dwoma datami

$dateTemp = clone $dateFrom;

//loop literate single days between two dates ($dateFrom, $dateTo)
while ($dateTemp <= ($dateTo->setTime(23, 59, 59, 999999))) {

   $dateTemp->modify('+1 days');
}

lub

<?php
$begin = new DateTime('2019-09-01');
$end = new DateTime('2019-09-10');

$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($begin, $interval, $end);

foreach ($period as $dt) {
    echo $dt->format("l Y-m-d H:i:s\n");
}
Komentarze wyłączone