I am working on a multilingual formular and have to solve a date formatting problem:
In German the date format is: DD-MM-YYYY While in another country e.g. England the date format is: YYYY-MM-DD
While this input validation is handled right, I need to get a easy solution for my php script to handle different date formats. In my MySQL-Database the field is created as a "date" field.
I already thought about a function like this:
<?
if($lang == "de") {
$date = $_POST['date'];
$toConvert = DateTime::createFromFormat('d-m-Y', $date);
$convertedDate = $toConvert->format('Y-m-d');
}
But isn't there a simpler solution as checking all countries with a different time format than Y-m-d? Maybe a library or something? I haven't found anyhting ..
Best regards DB-Dzine