3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dateRange = '2014-01-01 - 2014-01-08'; $parts = explode(' - ', $dateRange); $begin = new \DateTime($parts[0]); $end = new \DateTime($parts[1]); $interval = new \DateInterval('P1D'); $datePeriod = new \DatePeriod($begin, $interval, $end, DatePeriod::EXCLUDE_START_DATE); $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 5.4.30 - 5.4.45, 5.5.14 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
2014-01-02T00:00:00+01:00 2014-01-07T00:00:00+01:00 Array ( [0] => DateTime Object ( [date] => 2014-01-02 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) [1] => DateTime Object ( [date] => 2014-01-03 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) [2] => DateTime Object ( [date] => 2014-01-04 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) [3] => DateTime Object ( [date] => 2014-01-05 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) [4] => DateTime Object ( [date] => 2014-01-06 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) [5] => DateTime Object ( [date] => 2014-01-07 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) ) 1
Output for 7.3.32 - 7.3.33, 7.4.26, 8.0.13
2014-01-02T00:00:00+00:00 2014-01-07T00:00:00+00:00 Array ( [0] => DateTime Object ( [date] => 2014-01-02 00:00:00.000000 [timezone_type] => 3 [timezone] => UTC ) [1] => DateTime Object ( [date] => 2014-01-03 00:00:00.000000 [timezone_type] => 3 [timezone] => UTC ) [2] => DateTime Object ( [date] => 2014-01-04 00:00:00.000000 [timezone_type] => 3 [timezone] => UTC ) [3] => DateTime Object ( [date] => 2014-01-05 00:00:00.000000 [timezone_type] => 3 [timezone] => UTC ) [4] => DateTime Object ( [date] => 2014-01-06 00:00:00.000000 [timezone_type] => 3 [timezone] => UTC ) [5] => DateTime Object ( [date] => 2014-01-07 00:00:00.000000 [timezone_type] => 3 [timezone] => UTC ) ) 1
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.29, 5.5.0 - 5.5.13
2014-01-02T00:00:00+01:00 2014-01-07T00:00:00+01:00 Array ( [0] => DateTime Object ( [date] => 2014-01-02 00:00:00 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) [1] => DateTime Object ( [date] => 2014-01-03 00:00:00 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) [2] => DateTime Object ( [date] => 2014-01-04 00:00:00 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) [3] => DateTime Object ( [date] => 2014-01-05 00:00:00 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) [4] => DateTime Object ( [date] => 2014-01-06 00:00:00 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) [5] => DateTime Object ( [date] => 2014-01-07 00:00:00 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) ) 1
Output for 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 7 Fatal error: Class 'DateInterval' not found in /in/OtqtA on line 6
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 7 Fatal error: Class 'DateTime' not found in /in/OtqtA on line 4
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 7 Parse error: syntax error, unexpected ')', expecting '(' in /in/OtqtA on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 7 Parse error: parse error, unexpected ')', expecting '(' in /in/OtqtA on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/OtqtA on line 7 Parse error: parse error, expecting `'('' in /in/OtqtA on line 7
Process exited with code 255.

preferences:
290.39 ms | 402 KiB | 460 Q