<?php
$start = new DateTime('2012-07-01');
$interval = new DateInterval('P7D');
$end = new DateTime('2012-07-31');
$recurrences = 4;
$iso = 'R4/2012-07-01T00:00:00Z/P7D';
// All of these periods are equivalent.
$p = new DatePeriod($start, $interval, $recurrences);
//$p = new DatePeriod($start, $interval, $end);
//$p = new DatePeriod($iso);
foreach ($p as $d) {
echo $d->format('d ');
}
echo "\n";
$p = \PHP_VERSION_ID >= 70107
? clone $p
: new \DatePeriod(
$p->getStartDate(),
new \DateInterval($p->getDateInterval()->format('P%yY%mM%dDT%hH%iM%sS')),
$p->getEndDate() ?: $p->recurrences,
(int) $p->include_start_date
)
;
foreach ($p as $d) {
echo $d->format('d ');
}
- Output for 7.1.7 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
- 01 08 15 22 29
01 08 15 22 29
- Output for 5.6.20 - 5.6.40, 7.0.5 - 7.0.33, 7.1.0 - 7.1.6
- 01 08 15 22 29
08 15 22 29 05
- Output for 5.6.5 - 5.6.19, 7.0.0 - 7.0.4
- 01 08 15 22 29
Process exited with code 139. - Output for 5.6.0 - 5.6.4
- 01 08 15 22 29
Fatal error: Call to undefined method DatePeriod::getStartDate() in /in/hX9KD on line 23
Process exited with code 255.
preferences:
222.09 ms | 401 KiB | 292 Q