Given that some dates are valid, but can point to two different actual dates, no function can ever βguessβ the correct format at any time ...
To help with this, a new function has been added with PHP> = 5.3: date_create_from_format - but it does not exist with PHP <5.3, unfortunately ...
(See also DateTime::createFromFormat )
However, in the example you took, 1957 is a possible source of problems: PHP usually works with UNIX timestamps when it comes to dates ...
And, at least on 32-bit systems, they can only represent dates between 1970 and 2038 , as they count the number of seconds since 1970-01-01.
To avoid this problem, it is often recommended to use the DateTime class, with which ( quoting ):
Information about the date and time is internally stored as a 64-bit number, therefore all conceivable dates (including negative years). the range is about 292 billion years in the past and also in the future.
(This will not solve the parsing problem with PHP 5.3, but it will solve the problem with dates ...)
source share