dongxun6690 2019-05-19 07:38
浏览 403

Php bug与日期有关

when i edit the data and after the submission of that form, i got an error like

ERROR - 2019-05-19 12:40:26 --> Severity: error --> Exception: Call to a member function format() on boolean please help me out of this....

i followed this but its not working Call to a member function format() on boolean in PHP LARAVEL

$datetime = DateTime::createFromFormat('d/m/Y H:i:s', $date . ' ' . $time);
$created_at = $datetime->format('Y-m-d H:i:s');

$record = ['created_at' => $created_at,];
  • 写回答

2条回答 默认 最新

  • douqing5981 2019-05-19 07:52
    关注

    The issue is with the $date or $time string(s) you are trying to pass into DateTime::createFromFormat. They should look similar to the following to work properly:

    $date = "15/05/2019";
    $time = "10:28:33";
    
    $datetime = DateTime::createFromFormat('d/m/Y H:i:s', $date . ' ' . $time);
    $created_at = $datetime->format('Y-m-d H:i:s');
    
    $record = ['created_at' => $created_at,];
    
    print_r($record);
    

    Output:

    Array
    (
        [created_at] => 2019-05-15 10:28:33
    )
    
    评论

报告相同问题?