3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /** * @param Int $days * @return DatePeriod */ function getNumDays($days) { $today = new \DateTime('UTC'); $oneDay = new \DateInterval('P1D'); return new \DatePeriod($today, $oneDay, $days); } foreach(getNumDays(7) as $day){ //Do what ever you want with the DateTime instance //We'll just var_dump() it for now. var_dump($day); }
Output for 7.1.0
object(DateTime)#1 (3) { ["date"]=> string(26) "2014-10-16 11:19:26.004013" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#4 (3) { ["date"]=> string(26) "2014-10-17 11:19:26.004013" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-10-18 11:19:26.004013" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#4 (3) { ["date"]=> string(26) "2014-10-19 11:19:26.004013" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-10-20 11:19:26.004013" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#4 (3) { ["date"]=> string(26) "2014-10-21 11:19:26.004013" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-10-22 11:19:26.004013" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#4 (3) { ["date"]=> string(26) "2014-10-23 11:19:26.004013" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
Output for 5.6.28, 7.0.14
object(DateTime)#1 (3) { ["date"]=> string(26) "2014-10-16 11:19:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#4 (3) { ["date"]=> string(26) "2014-10-17 11:19:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-10-18 11:19:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#4 (3) { ["date"]=> string(26) "2014-10-19 11:19:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-10-20 11:19:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#4 (3) { ["date"]=> string(26) "2014-10-21 11:19:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-10-22 11:19:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#4 (3) { ["date"]=> string(26) "2014-10-23 11:19:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
Output for 5.4.30 - 5.4.45, 5.5.14 - 5.6.22, 7.0.0 - 7.0.7
object(DateTime)#1 (3) { ["date"]=> string(26) "2013-10-03 10:43:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#4 (3) { ["date"]=> string(26) "2013-10-04 10:43:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#1 (3) { ["date"]=> string(26) "2013-10-05 10:43:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#4 (3) { ["date"]=> string(26) "2013-10-06 10:43:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#1 (3) { ["date"]=> string(26) "2013-10-07 10:43:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#4 (3) { ["date"]=> string(26) "2013-10-08 10:43:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#1 (3) { ["date"]=> string(26) "2013-10-09 10:43:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#4 (3) { ["date"]=> string(26) "2013-10-10 10:43:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
Output for hhvm-3.10.0 - 3.12.0
object(DateTime)#8 (3) { ["date"]=> string(26) "2013-10-03 12:43:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#8 (3) { ["date"]=> string(26) "2013-10-04 12:43:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#8 (3) { ["date"]=> string(26) "2013-10-05 12:43:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#8 (3) { ["date"]=> string(26) "2013-10-06 12:43:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#8 (3) { ["date"]=> string(26) "2013-10-07 12:43:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#8 (3) { ["date"]=> string(26) "2013-10-08 12:43:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#8 (3) { ["date"]=> string(26) "2013-10-09 12:43:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#8 (3) { ["date"]=> string(26) "2013-10-10 12:43:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
Output for 5.3.0 - 5.4.29, 5.5.0 - 5.5.13
object(DateTime)#1 (3) { ["date"]=> string(19) "2013-10-03 10:43:36" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#4 (3) { ["date"]=> string(19) "2013-10-04 10:43:36" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#1 (3) { ["date"]=> string(19) "2013-10-05 10:43:36" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#4 (3) { ["date"]=> string(19) "2013-10-06 10:43:36" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#1 (3) { ["date"]=> string(19) "2013-10-07 10:43:36" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#4 (3) { ["date"]=> string(19) "2013-10-08 10:43:36" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#1 (3) { ["date"]=> string(19) "2013-10-09 10:43:36" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTime)#4 (3) { ["date"]=> string(19) "2013-10-10 10:43:36" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
Output for 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RYQbk on line 8 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RYQbk on line 9 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RYQbk on line 11 Fatal error: Class 'DateInterval' not found in /in/RYQbk on line 9
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RYQbk on line 8 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RYQbk on line 9 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RYQbk on line 11 Fatal error: Class 'DateTime' not found in /in/RYQbk on line 8
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RYQbk on line 8 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RYQbk on line 9 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RYQbk on line 11 Fatal error: Cannot instantiate non-existent class: datetime in /in/RYQbk on line 8
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RYQbk on line 8 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RYQbk on line 9 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RYQbk on line 11 Fatal error: Cannot instantiate non-existent class: datetime in /in/RYQbk on line 8