Tag Archives: date

How to convert a timestamp into a readable date in PHP

A UNIX timestamp is something like a 10 digit (or less) integer number which represents the elapsed seconds since the 1st of January 1970 (also known as the Unix Epoch). It’s a very accurate representation of time, but not necessarily something us humans easily understand.

A Unix Timestamp looks something like 1367805780.

We can use PHP’s date() function to turn it into something more readable, such as 05/05/2013, or 5th of May, 2013 at 10:03pm. Here’s how:

The first parameter tells date() how to format its output – and you can get extremely creative with it:

The slightly eerie looking combination of letters and numbers is made up of “real” printable characters (such as the “of” in “5th of May”) and special switches that represent each date component.

For a full reference and plenty of examples have a look at the PHP Manual: