Hi everyone I have a form that accepts user date entry in the form
dd/mm/yyyy
and converts it to US date in the form
yyyy-mm-dd
How can I return an error if the user does not type in the date in the correct format initially? e.g. 12/2012
This is the code I have so far.
// collect values from a form sent with method=get
$uk_date = $_GET["date"];
// convert between date formats
$parts = explode("/", $uk_date, 3);
$us_date = $parts[2] . "-" . $parts[1] . "-" . $parts[0];
echo $us_date.'<br>';
Thanks in advance!
I am using PHP btw.
Instead of validating the date, why not just convert the date to the correct format after the form is submitted? That way the user can enter the date in any format they want