In our webapp, users can import their own data. One of the parameters in an Excel file is a date. Users will often upload different kinds of formats. One user will upload dd-mm-yy
while another will upload yy-mm-dd
or dd/mm/YYYY
.
Now, I wrote the code below to parse some of them.
$buydate = str_replace("\\", "-", $buydate);
$buydate = str_replace("/", "-", );
$buydate = date("Y-m-d", strtotime($buydate));
However, when a user uploads dd-mm-yy
my code will often use the wrong number as the year. Is there a method to parse all possible date strings to one date format?