How to convert a timestamp into a readable date in PHP

- by

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:

	$theTimestamp = 1367805780;
	echo date('m/d/Y', $theTimestamp);

	// result: 05/05/2013

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

	$theTimestamp = 1367805780;
	echo date('l jS \of F Y h:i:sa', $theTimestamp);

	// result: Sunday 5th of May 2013 10:03:00pm

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:



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.