3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $dateRange = '2014-01-01 - 2014-01-08'; $parts = explode(' - ', $dateRange); $begin = new \DateTime($parts[0]); $end = new \DateTime($parts[1]); $interval = new \DateInterval('M1D'); $datePeriod = new \DatePeriod($begin, $interval, $end); $periodArray = iterator_to_array($datePeriod); $startDate = reset($periodArray); $endDate = end($periodArray); #echo $datePeriod->start->format('c'); #echo "\n"; echo $startDate->format('c'); echo "\n"; #echo "\n"; #echo $datePeriod->end->format('c'); #echo "\n"; echo $endDate->format('c'); echo "\n"; echo "\n"; echo print_r($periodArray);
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Exception: DateInterval::__construct(): Unknown or bad format (M1D) in /in/aBCB2:6 Stack trace: #0 /in/aBCB2(6): DateInterval->__construct('M1D') #1 {main} thrown in /in/aBCB2 on line 6
Process exited with code 255.
Output for 5.3.0 - 5.6.28
Fatal error: Uncaught exception 'Exception' with message 'DateInterval::__construct(): Unknown or bad format (M1D)' in /in/aBCB2:6 Stack trace: #0 /in/aBCB2(6): DateInterval->__construct('M1D') #1 {main} thrown in /in/aBCB2 on line 6
Process exited with code 255.
Output for 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aBCB2 on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aBCB2 on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aBCB2 on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aBCB2 on line 7 Fatal error: Class 'DateInterval' not found in /in/aBCB2 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/aBCB2 on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aBCB2 on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aBCB2 on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aBCB2 on line 7 Fatal error: Class 'DateTime' not found in /in/aBCB2 on line 4
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aBCB2 on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aBCB2 on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aBCB2 on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aBCB2 on line 7 Fatal error: Cannot instantiate non-existent class: datetime in /in/aBCB2 on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aBCB2 on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aBCB2 on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aBCB2 on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/aBCB2 on line 7 Fatal error: Cannot instantiate non-existent class: datetime in /in/aBCB2 on line 4