"Call to a member function format() on a non-object" when converting date in PHP -
i can not rid of error message:
call member function format() on non-object
so, go on googling , source this stackoverflow question.
i tried similar, failed. code :
$temp = new datetime(); /*error here*/ $data_umat['tanggal_lahir'] = $data_umat['tanggal_lahir']->format('y-m-d'); $data_umat['tanggal_lahir'] = $temp;
so, did trial & errors, , found out if this:
$data_umat['tanggal_lahir'] = date("y-m-d h:i:s");
the date converted, return today's date (which dont want).
i want convert date 10/22/2013
2013-10-22
.
you calling method format()
on non-object. try this:
$data_umat['tanggal_lahir'] = new datetime('10/22/2013'); $data_umat['tanggal_lahir'] = $data_umat['tanggal_lahir']->format('y-m-d');
or one-liner:
$data_umat['tanggal_lahir'] = date_create('10/22/2013')->format('y-m-d');
Comments
Post a Comment