<?PHP
function mysql_date($in) {
//Function takes a string in as form data, splits it by a list of
//possible separators. If the resulting array has a length of 3, the
//function returns a MySQL compatible date() string, else returns false
//
//Also, uses the checkdate() [PHP core function] to validate the date.
$output = false;
$d = preg_split('#[-/:. ]#', trim($in));
if (is_array($d) && count($d) == 3) {
if (strlen($d[2]) == 2) {
$d[2] = '20'.$d[2];
}
if (checkdate($d[0], $d[1], $d[2])) {
$output = "$d[2]-$d[0]-$d[1]";
}
}
return $output;
}
echo mysql_date('05/07/2014');