Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 from the database and convert it to ISO 8601 format.

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

Currently, my timestamps are in the database in this format:

0000-00-00 00:00:00

I have tried using timeago with my currently formatted timestamp, but it doesn't work. It just always says 'less than a minute ago.'

However, when I hardcode it in the ISO 8601 format, it works. Therefore, I need some help on either:

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

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

Many thanks!!

like image 570
Dodinas Avatar asked Dec 29 '22 11:12

Dodinas


1 Answers

Try using the result from your SELECT statement in something like this:

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

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

like image 101
BraedenP Avatar answered Jan 01 '23 00:01

BraedenP