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

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
    )
    
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题