3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $in = trim('March 8 - 10'); $now = new DateTime(); // Defaults to now $start = DateTime::createFromFormat('F j+', $in); // Parse month and day, ignore the rest if ($now > $start) { $start->modify("next year"); } $end = clone $start; $end->setDate( $end->format('Y'), // $start year $end->format('n'), // $start month substr($in, strrpos($in, ' ') + 1) // trailing bit of $in for day ); echo $start->format("Y-m-d"), "\n"; echo $end->format("Y-m-d");
Output for 5.3.9 - 5.4.45, 5.5.33, 5.6.19, 5.6.28, 7.0.20 - 7.2.0
2016-03-08 2016-03-10
Output for 5.5.24 - 5.5.32, 5.5.34 - 5.6.18, 5.6.20 - 5.6.21, 7.0.0 - 7.0.6
2017-03-08 2017-03-10
Output for 5.3.0 - 5.3.8
Fatal error: Call to a member function modify() on a non-object in /in/YUrqf on line 10
Process exited with code 255.
Output for 5.2.10 - 5.2.17
Fatal error: Call to undefined method DateTime::createFromFormat() in /in/YUrqf on line 7
Process exited with code 255.
Output for 5.2.0 - 5.2.9
Fatal error: Call to undefined method DateTime::createfromformat() in /in/YUrqf on line 7
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/YUrqf on line 6
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_VARIABLE in /in/YUrqf on line 13
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/YUrqf on line 13
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/YUrqf on line 13
Process exited with code 255.