3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $startDate = new DateTime('2014-05-01'); $endDate = new DateTime('2014-06-02'); // calculate diff $diff = $startDate->diff($endDate); $daysDiff = $diff->days; for ($i = 0; $i < $daysDiff; $i++) { // clone so the original date will not be changed $currentDate = clone $startDate; $currentDate->modify('+'.$i.' days'); echo $currentDate->format('Y-m-d H:i:s')."\n"; }
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
2014-05-01 00:00:00 2014-05-02 00:00:00 2014-05-03 00:00:00 2014-05-04 00:00:00 2014-05-05 00:00:00 2014-05-06 00:00:00 2014-05-07 00:00:00 2014-05-08 00:00:00 2014-05-09 00:00:00 2014-05-10 00:00:00 2014-05-11 00:00:00 2014-05-12 00:00:00 2014-05-13 00:00:00 2014-05-14 00:00:00 2014-05-15 00:00:00 2014-05-16 00:00:00 2014-05-17 00:00:00 2014-05-18 00:00:00 2014-05-19 00:00:00 2014-05-20 00:00:00 2014-05-21 00:00:00 2014-05-22 00:00:00 2014-05-23 00:00:00 2014-05-24 00:00:00 2014-05-25 00:00:00 2014-05-26 00:00:00 2014-05-27 00:00:00 2014-05-28 00:00:00 2014-05-29 00:00:00 2014-05-30 00:00:00 2014-05-31 00:00:00 2014-06-01 00:00:00
Output for 5.2.0 - 5.2.17
Fatal error: Call to undefined method DateTime::diff() in /in/RmNGq on line 5
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/RmNGq on line 2
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_VARIABLE in /in/RmNGq on line 11
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_VARIABLE in /in/RmNGq on line 11
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/RmNGq on line 11
Process exited with code 255.