php - DateTime Object Error: Call to a member function format() on boolean -


fatal error: uncaught error: call member function format() on boolean in /homepages/21/*****/*****/******/card/upload.php:29 stack trace: #0 {main} thrown in /homepages/21/******/*****/*****/card/upload.php on line 29

$newarray['date'] = datetime::createfromformat("j m y", $arry[0])->format("y-m-d"); 

how can fix problem?

it clear passing invalid date expression via $arry[0].

here demo:

// works when $arry[0] valid $arry=['28 jan 2017']; $newarray['date'] = datetime::createfromformat("j m y", $arry[0])->format("y-m-d"); echo $newarray['date'];  echo "\n\n";  // doesn't otherwise $arry=['28 mon 2017'];  // or empty string, etc. $newarray['date'] = datetime::createfromformat("j m y", $arry[0])->format("y-m-d"); echo $newarray['date']; 

output:

2017-01-28  <br /> <b>fatal error</b>:  uncaught error: call member function format() on boolean in [...][...]:16 stack trace: #0 {main}   thrown in <b>[...][...]</b> on line <b>16</b><br /> 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -