3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $weekModifier = 1; $date = new DateTime(); if($date->format('N') !== 1) { $date->sub(new DateInterval('P'. $date->format('N') . 'D')); } $interval = new DateInterval('P'.abs($weekModifier).'W'); if($weekModifier > 0) { $date->add($interval); } else { $date->sub($interval); } for($i = 1; $i <= 7; $i++) { echo $date->add(new DateInterval('P1D'))->format('l Y-m-d') . "<br>\n"; } ?>
Output for 5.6.28, 7.0.12 - 7.1.0
Monday 2014-05-19<br> Tuesday 2014-05-20<br> Wednesday 2014-05-21<br> Thursday 2014-05-22<br> Friday 2014-05-23<br> Saturday 2014-05-24<br> Sunday 2014-05-25<br>
Output for 7.0.6
Monday 2016-05-09<br> Tuesday 2016-05-10<br> Wednesday 2016-05-11<br> Thursday 2016-05-12<br> Friday 2016-05-13<br> Saturday 2016-05-14<br> Sunday 2016-05-15<br>
Output for 5.5.0 - 5.5.34, 5.6.0 - 5.6.20, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.0.5
Monday 2016-04-18<br> Tuesday 2016-04-19<br> Wednesday 2016-04-20<br> Thursday 2016-04-21<br> Friday 2016-04-22<br> Saturday 2016-04-23<br> Sunday 2016-04-24<br>
Output for 5.6.21
Monday 2016-05-02<br> Tuesday 2016-05-03<br> Wednesday 2016-05-04<br> Thursday 2016-05-05<br> Friday 2016-05-06<br> Saturday 2016-05-07<br> Sunday 2016-05-08<br>
Output for 5.5.35
Monday 2016-05-23<br> Tuesday 2016-05-24<br> Wednesday 2016-05-25<br> Thursday 2016-05-26<br> Friday 2016-05-27<br> Saturday 2016-05-28<br> Sunday 2016-05-29<br>
Output for 5.4.0 - 5.4.45
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.' in /in/9Fi1l:5 Stack trace: #0 /in/9Fi1l(5): DateTime->__construct() #1 {main} thrown in /in/9Fi1l on line 5
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead' in /in/9Fi1l:5 Stack trace: #0 /in/9Fi1l(5): DateTime->__construct() #1 {main} thrown in /in/9Fi1l on line 5
Process exited with code 255.
Output for 5.2.3 - 5.2.17
Fatal error: Call to undefined method DateTime::sub() in /in/9Fi1l on line 8
Process exited with code 255.
Output for 5.2.0 - 5.2.2
<br /> <b>Fatal error</b>: Call to undefined method DateTime::sub() in <b>/in/9Fi1l</b> on line <b>8</b><br />
Process exited with code 255.
Output for 5.0.0 - 5.1.6
<br /> <b>Fatal error</b>: Class 'DateTime' not found in <b>/in/9Fi1l</b> on line <b>5</b><br />
Process exited with code 255.
Output for 4.4.2 - 4.4.9
<br /> <b>Parse error</b>: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in <b>/in/9Fi1l</b> on line <b>20</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
<br /> <b>Parse error</b>: parse error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in <b>/in/9Fi1l</b> on line <b>20</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Parse error</b>: parse error, expecting `','' or `';'' in <b>/in/9Fi1l</b> on line <b>20</b><br />
Process exited with code 255.