3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function validateDate($date, $format = 'Y-m-d H:i:s') { $d = DateTime::createFromFormat($format, $date); var_dump($d); echo "----------------------------------\n"; echo $d->format($format); echo "----------------------------------\n"; echo $date; echo "----------------------------------\n"; echo $d && $d->format($format) == $date; return; } validateDate('2012-02-30 12:12:12'); validateDate('30/02/2012', 'd/m/Y'); validateDate('14:77', 'H:i'); validateDate('2012-02-28 12:12:12');
based on fctp7
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0alpha1
object(DateTime)#1 (3) { ["date"]=> string(26) "2012-03-01 12:12:12.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } ---------------------------------- 2012-03-01 12:12:12---------------------------------- 2012-02-30 12:12:12---------------------------------- object(DateTime)#1 (3) { ["date"]=> string(26) "2012-03-01 18:21:24.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } ---------------------------------- 01/03/2012---------------------------------- 30/02/2012---------------------------------- object(DateTime)#1 (3) { ["date"]=> string(26) "2017-06-14 15:17:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } ---------------------------------- 15:17---------------------------------- 14:77---------------------------------- object(DateTime)#1 (3) { ["date"]=> string(26) "2012-02-28 12:12:12.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } ---------------------------------- 2012-02-28 12:12:12---------------------------------- 2012-02-28 12:12:12---------------------------------- 1