how to change date format on this html user form

前端 未结 3 1555
抹茶落季
抹茶落季 2021-01-27 09:22

I have the html form which enter data into mysql DB, but in input field of date it has this format,

(mm/dd/yyyy) 

BUT I prefer to use this form

3条回答
  •  猫巷女王i
    2021-01-27 10:16

    You should be storing your dates as actual dates and not strings. You're only making your life more difficult by storing them in a non-standard format.

    But if you insist on using this format, this code will work for you:

    $original = DateTime::createFromFormat('m/d/Y', '04/18/1973');
    $date     = $original->format('d/m/Y');
    

提交回复
热议问题