Search code examples
phpmysqlunix-timestampdate-formatting

Formatting date to human readable format


Lets say in my mysql database I have a timestamp 2013-09-30 01:16:06 and lets say this variable is $ts.

How can I output this to show more like September 30th, 2013?


Solution

  • $timestamp = "2013-09-30 01:16:06";
    echo date("F jS, Y", strtotime($timestamp)); //September 30th, 2013
    

    Note the use of S to get the english ordinal suffix for the day.
    Since you're already using strtotime if you need a human readable data for the current time you can just use the keyword "now" as in strtotime("now")

    Related sources