如何解决致命错误“在865行的/xyz/pqr/prj_name/functions/common.php中对非对象调用成员函数格式()”?

Following is the necessary code from file "/xyz/pqr/prj_name/functions/common.php"

function format_date_yyyy_mm_dd($date_val) {
  $date = DateTime::createFromFormat('n-j-Y', $date_val);
  return $date->format('Y-m-d');  //Thie is line no.865 where I'm getting the error.
}

This file has been included into the file where the function format_date_yyyy_mm_dd() is called.

The code for calling the function is as follows :

$form_data['reg_date'] = format_date_yyyy_mm_dd($form_data['reg_date']);

Can some one please help in correcting the code I've written and help me where my code is going wrong?

Thanks in advance.

You code is correct, please check the value of $form_data['reg_date'] and make sure it is something like 12-19-2014 and it should be month-date-year. You may passing wrong format of date from your form.

echo format_date_yyyy_mm_dd('12-19-2014');