Select ISO 8601 timestamp from MySQL database

I am currently using PHP / MySQL and the jQuery timeago plugin. Basically, I need to pull my timestamp out of the database and convert it to the ISO 8601 format.

Like this 2008-07-17T09:24:17Z

My timestamps are currently in the database in this format:

0000-00-00 00:00:00

I tried using timeago with my formatted timestamp, but this does not work. He just says "less than a minute ago."

However, when I hardcode it in ISO 8601 format, it works. So I need help:

1) Using SELECT statement to convert my timestamp to ISO 8601 format

2) Or, SELECT a timestamp, and then convert to ISO 8601 with PHP.

Many thanks!

+4
source share
1 answer

Try using the result from the SELECT statement like this:

 $iso_date = date('c',strtotime($selected_timestamp)); 

This will use the $ selected_timestamp variable from your db, convert it to a PHP timestamp, and then output the ISO 8601 timestamp to $ iso_date.

+10
source

All Articles