php convert date to MySQL date

后端 未结 4 1461
盖世英雄少女心
盖世英雄少女心 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:40

    There are two options you can use which are strtotime or preg_split and sprintf. I recommend you use strtotime. The structure goes like this:

    $date = 'November 28 2009';
    $sqldate = date('Y-m-d', strtotime($date));
    

    Make sure the Y is capital so it reads as 0000 otherwise it will read 00.

提交回复
热议问题