@ 2015-11-26T10:47:48Z <?php
$utc = new DateTimeZone('UTC');
$start = new DateTime('2015-09-01', $utc);
$end = new DateTime('2015-09-02', $utc);
$interval = new DateInterval('P1D');
$period = new DatePeriod($start, $interval, $end);
foreach ($period as $current) {
$currentEnd = clone $current;
$currentEnd->add($period->interval);
var_dump($current, $currentEnd);
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 object(DateTime)#10 (3) {
["date"]=>
string(26) "2015-09-01 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
object(DateTime)#11 (3) {
["date"]=>
string(26) "2015-09-02 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
Output for 7.1.7 - 7.1.20 , 7.2.0 - 7.2.33 , 7.3.16 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 object(DateTime)#7 (3) {
["date"]=>
string(26) "2015-09-01 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
object(DateTime)#8 (3) {
["date"]=>
string(26) "2015-09-02 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
Output for 5.5.24 - 5.5.35 , 5.6.8 - 5.6.21 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.6 Warning: DateTime::add(): The DateInterval object has not been correctly initialized by its constructor in /in/QnFGS on line 11
object(DateTime)#7 (3) {
["date"]=>
string(26) "2015-09-01 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
object(DateTime)#8 (3) {
["date"]=>
string(26) "2015-09-01 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
preferences:dark mode live preview
164.06 ms | 403 KiB | 182 Q