Formatting an SQL timestamp with PHP

后端 未结 6 552
無奈伤痛
無奈伤痛 2020-12-01 16:15

I have a mySQL database with a timestamp field. It currently only has one entry while I\'m testing, it is

2010-02-20 13:14:09

I am pulling

6条回答
  •  天涯浪人
    2020-12-01 16:48

    You could just use MySQL's date_format() function instead:

    SELECT date_format(timestampfield, '%m-%d-%Y') FROM table etc....
    

    This will save you having to round-trip your timestamp into unix time and then back into a normal date string in PHP. One datetime formatting call rather than two.

提交回复
热议问题