Alex Rivera | Logout

Convert Unix timestamp into human readable date using MySQL

Asked 2011-06-07T15:23:30.297
292

Is there a MySQL function which can be used to convert a Unix timestamp into a human readable date? I have one field where I save Unix times and now I want to add another field for human readable dates.

Edit
Report

2 Answers

524

Use FROM_UNIXTIME():

SELECT
  FROM_UNIXTIME(timestamp) 
FROM 
  your_table;

See also: MySQL documentation on FROM_UNIXTIME().

answered 2011-06-07T15:28:00.457
7

Why bother saving the field as readable? Just us AS

SELECT theTimeStamp, FROM_UNIXTIME(theTimeStamp) AS readableDate
               FROM theTable
               WHERE theTable.theField = theValue;

EDIT: Sorry, we store everything in milliseconds not seconds. Fixed it.

answered 2011-06-07T15:27:50.720

Your Answer