Your date is a valid date, however your code is incorrect in that DateTime::createFromFormat()
is a static function as is getLastErrors()
. Your example code should be:-
$date_test = '13-10-31';
$date = \DateTime::createFromFormat('Y-m-d', $date_test);
$date_errors = \DateTime::getLastErrors();
print_r($date_errors);
However, there will still be no errors as the 31st October 13 (13-10-31) is a valid date. When you provide '13'
as the year, DateTime casts it to an integer, 13
, therefore, it is a valid year.
If you want to discard double digit years as invalid, then you will have to write your own validation functions.
I would recommend a thorough read of the PHP Date and Time extensions documentation