3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $in = trim('November 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");
based on YUrqf
Output for 5.3.18 - 5.4.45, 5.6.28, 7.0.20 - 7.2.0
2015-11-08 2015-11-10
Output for 5.5.24 - 5.6.21, 7.0.0 - 7.0.6
2016-11-08 2016-11-10