如何解决致命错误“在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.
以下是文件“ 此文件已包含在函数 调用该函数的代码如下: p>
有人可以帮助纠正我编写的代码并帮助我在哪里编写代码 出错了? p>
提前致谢。 p>
div> /xyz/pqr/prj_name/functions/common.php “ p>
function format_date_yyyy_mm_dd($ date_val){
$ date = DateTime :: createFromFormat('nj-Y',$ date_val);
返回$ date - >格式( 'YM-d'); //这是第865行,我收到错误。
}
code> pre>
的文件中 调用format_date_yyyy_mm_dd() code>。 p>
$ form_data ['reg_date '] = format_date_yyyy_mm_dd($ form_data ['reg_date']);
code> pre>
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');