3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function validateDateA($date, $format = 'Y-m-d') { $dt = DateTime::createFromFormat($format, $date); return $dt && $dt->format($format) == $date; } function validateDateB($date, $format = 'Y-m-d') { DateTime::createFromFormat($format, $date); $a = DateTime::getLastErrors(); return !$a['warning_count'] && !$a['error_count']; } var_dump(validateDateA('Tue, 27 Feb 2012 12:12:12 +0200', DateTime::RSS)); # false var_dump(validateDateB('Tue, 27 Feb 2012 12:12:12 +0200', DateTime::RSS)); # true
Output for 5.3.0 - 7.1.0
bool(false) bool(true)