3

I have timestamps stored in datetime columns in a Mysql database. The timestamps are already in UTC time.

My PHP application needs to return the values in ISO 8601 format.

Is it better to convert them using PHP ex:

date('c', strtotime($sqldata['my_date_field']));

Or using MySql's DATE_FORMAT function? ex:

DATE_FORMAT(my_date_field,'%Y-%m-%dT%TZ')

I'm trying to consider speed, accuracy, and best practice.

TimSum
  • 738
  • 2
  • 8
  • 21
  • 1
    Store your values in unix time. If you insist on storing them as datetime then use whichever one you are more familiar with and don't mind debugging. – Dimi Mar 23 '17 at 16:38
  • PHP - that way you can convert to other formats for display, extract parts (e.g., just date or just time), convert to local timezone, etc. The time to convert the date from one format to another - whether in MySQL or PHP - is extremely small. – manassehkatz-Moving 2 Codidact Mar 23 '17 at 16:41
  • See here http://stackoverflow.com/questions/2533767/mysql-whats-the-best-to-use-unix-timestamp-or-datetime – Yolo Mar 23 '17 at 17:42

0 Answers0