How to create DateTime object from string in symfony2/php

前端 未结 3 1810
南方客
南方客 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条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-08 00:13

    How about createFromFormat?

    http://uk.php.net/manual/en/datetime.createfromformat.php

    $from = DateTime::createFromFormat($post['started_at'], 'Y-m-d H:i:s');
    

提交回复
热议问题