php convert date to MySQL date

后端 未结 4 1428
盖世英雄少女心
盖世英雄少女心 2021-01-24 03:11

I need to convert a date in this format:

November 28, 2009

to a MySQL date format:

2009-28-11

4条回答
  •  不思量自难忘°
    2021-01-24 03:58

    If you want a "date" to be converted to "DateTime" this is the best way =

    // for example: you have a string with the following
    $dateFormat = 'd/m/Y';
    $dateString = '02/12/2019';
    
    // you can easily create DateTime using
    $dateTime = \DateTime::createFromFormat($dateFormat, $dateString);
    

    As described in the php documentation for createFromFormat.

    And to answer completely on your question:

    echo $dateTime->format('y-m-d');
    

提交回复
热议问题