3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $input_date = '1/12/2015'; $date = \DateTime::createFromFormat('Y-m-d', $input_date); if (empty($date)) { $date = \DateTime::createFromFormat('m/d/Y', $input_date); if (empty($date)) { throw new \Exception("Date field '$field' not in the required format (MM/DD/YYYY or YYYY-MM-DD)."); } } var_dump($date);
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.1.1, 7.1.3 - 7.3.0rc3
object(DateTime)#1 (3) { ["date"]=> string(26) "2015-01-12 22:46:52.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for hhvm-3.15.4, 7.1.2
object(DateTime)#1 (3) { ["date"]=> string(26) "2015-01-12 22:46:53.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }