Consider my method :
static public function mysqldate($c,$f = 'd-M-y'){
// date is supposed to be in dd/MMM/yyyy format.
// returns a date in mysql form
try {
$result = "'" . DateTime::createFromFormat($f,$c)->format('Y-m-d') . "'";
}
catch (Exception $e){
$error = "error in mysqldate <br />" ;
$error .= "date passed : " . $c . "<br />";
$error .= "error thrown : " . "<br />" . $e->getMessage() . "<br />";
$error .= "trace : " . "<br />". $e->gettrace() . "<br />";;
p0110error::terminal($error);
}
return $result;
}
It works fine when I pass it a valid date in d-M-y format like 17-mar-13. But when the date is not valid like say 17-ddd-13, it gives me a fatal error but the try catch is not triggered.
Why is that?
The error is "Fatal error: Call to a member function format() on a non-object in ..." (line 5).