How to create DateTime object from string in symfony2/php

前端 未结 3 1817
南方客
南方客 2021-02-07 23:48

In a DB table I have several fields with datetime as field type. So I need to persist data only as date time object.

From a form I get date time as string l

3条回答
  •  旧时难觅i
    2021-02-08 00:12

    i always create DateTime object with its constructor, os in your case it would be:

    $protocol->setStartedAt(new \DateTime($post['started_at']));
    

    if this works, but does not use the timestamp posted you probably do not have the value in $post['started_at']. Try debuging it or just do the dirty trick:

    die($post['started_at']);
    

提交回复
热议问题