[英]How to resolve the fatal error “Call to a member function format() on a non-object in /xyz/pqr/prj_name/functions/common.php on line 865”?
Following is the necessary code from file " /xyz/pqr/prj_name/functions/common.php
" 以下是文件“ /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. 该文件已包含在调用format_date_yyyy_mm_dd()
函数的文件中。
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
. 您输入的代码正确无误,请检查$form_data['reg_date']
的值,并确保该值类似于12-19-2014
,并且应为month-date-year
。 You may passing wrong format of date from your form. 您可能从表格中传递了错误的日期格式。
echo format_date_yyyy_mm_dd('12-19-2014');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.