Strtotime() doesn’t work with dd/mm/YYYY format

Here is the simplified solution:

$date="25/05/2010";
$date = str_replace("https://stackoverflow.com/", '-', $date);
echo date('Y-m-d', strtotime($date));

Result:

2010-05-25

The strtotime documentation reads:

Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash () or a dot (.), then the European d-m-y format is assumed.

Leave a Comment