Converting string to Date and DateTime

后端 未结 10 1701
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 17:07

If I have a PHP string in the format of mm-dd-YYYY (for example, 10-16-2003), how do I properly convert that to a Date and then a DateTime

10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 17:42

    Since no one mentioned this, here's another way:

    $date = date_create_from_format("m-d-Y", "10-16-2003")->format("Y-m-d");
    

提交回复
热议问题