3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $date_from = (new \DateTime("2015-03-28")); //->setTimezone(new \DateTimeZone('UTC')); $date_to = (new \DateTime("2015-03-30")); //->setTimezone(new \DateTimeZone('UTC')); $interval = \DateInterval::createFromDateString('1 hour'); while ($date_to > $date_from) { $foo = clone $date_to; $check = $date_to->sub($interval); if ($foo == $check) { die('error'); } else { $date_to = $check; } if ($date_to < $date_from) { $date_to = $date_from; } echo "\n\nFrom:".$date_to->format('d/m/Y H:i:s'); echo "\nTo:".$foo->format('d/m/Y H:i:s'); }
based on No2tY
Output for 5.3.0 - 7.2.0
From:29/03/2015 23:00:00 To:30/03/2015 00:00:00 From:29/03/2015 22:00:00 To:29/03/2015 23:00:00 From:29/03/2015 21:00:00 To:29/03/2015 22:00:00 From:29/03/2015 20:00:00 To:29/03/2015 21:00:00 From:29/03/2015 19:00:00 To:29/03/2015 20:00:00 From:29/03/2015 18:00:00 To:29/03/2015 19:00:00 From:29/03/2015 17:00:00 To:29/03/2015 18:00:00 From:29/03/2015 16:00:00 To:29/03/2015 17:00:00 From:29/03/2015 15:00:00 To:29/03/2015 16:00:00 From:29/03/2015 14:00:00 To:29/03/2015 15:00:00 From:29/03/2015 13:00:00 To:29/03/2015 14:00:00 From:29/03/2015 12:00:00 To:29/03/2015 13:00:00 From:29/03/2015 11:00:00 To:29/03/2015 12:00:00 From:29/03/2015 10:00:00 To:29/03/2015 11:00:00 From:29/03/2015 09:00:00 To:29/03/2015 10:00:00 From:29/03/2015 08:00:00 To:29/03/2015 09:00:00 From:29/03/2015 07:00:00 To:29/03/2015 08:00:00 From:29/03/2015 06:00:00 To:29/03/2015 07:00:00 From:29/03/2015 05:00:00 To:29/03/2015 06:00:00 From:29/03/2015 04:00:00 To:29/03/2015 05:00:00 From:29/03/2015 03:00:00 To:29/03/2015 04:00:00error
Output for 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/QXbUV on line 3 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/QXbUV on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/QXbUV on line 6 Fatal error: Class 'DateInterval' not found in /in/QXbUV on line 6
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/QXbUV on line 3 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/QXbUV on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/QXbUV on line 6 Fatal error: Class 'DateTime' not found in /in/QXbUV on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/QXbUV on line 3 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/QXbUV on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/QXbUV on line 6 Parse error: syntax error, unexpected T_VARIABLE in /in/QXbUV on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/QXbUV on line 3 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/QXbUV on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/QXbUV on line 6 Parse error: parse error, unexpected T_VARIABLE in /in/QXbUV on line 9
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/QXbUV on line 3 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/QXbUV on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/QXbUV on line 6 Parse error: parse error in /in/QXbUV on line 9
Process exited with code 255.