Convert from MySQL datetime to another format with PHP

后端 未结 18 1231
醉话见心
醉话见心 2020-11-22 01:08

I have a datetime column in MySQL.

How can I convert it to the display as mm/dd/yy H:M (AM/PM) using PHP?

18条回答
  •  遥遥无期
    2020-11-22 01:26

    SELECT 
     DATE_FORMAT(demo.dateFrom, '%e.%M.%Y') as dateFrom,
     DATE_FORMAT(demo.dateUntil, '%e.%M.%Y') as dateUntil
    FROM demo
    

    If you dont want to change every function in your PHP code, to show the expected date format, change it at the source - your database.

    It is important to name the rows with the as operator as in the example above (as dateFrom, as dateUntil). The names you write there are the names, the rows will be called in your result.

    The output of this example will be

    [Day of the month, numeric (0..31)].[Month name (January..December)].[Year, numeric, four digits]

    Example: 5.August.2015

    Change the dots with the separator of choice and check the DATE_FORMAT(date,format) function for more date formats.

提交回复
热议问题