Wednesday, 16 May 2012

PHP / Mysql methods of converting timestamp to DATE

php converting timestamp to DATE

$datetime = date("Y-m-d H:i:s", $timestamp);


using FROM_UNIXTIME will do it for you inside the mysql query itself.

take a look at this code

SELECT userId, url, FROM_UNIXTIME(epoch) FROM mytable

In my situation the Date in the Mysql was in DATE format and I wanted the result returned back to me in a UNIX timestamp  

Here's the query I used

$query = "SELECT UNIX_TIMESTAMP(shift_date) as shift_date FROM  `legacy_shifts` ";

No comments: