1

Hi I'm trying to convert my result out of a timestamp field into a formated way.

So from '2016-12-24 14:11:00' to '2016-12-24T14:11:00Z'

What is the easiest way to do so?

Giancarlo
  • 377
  • 2
  • 6
  • 16
  • What is that date format? It's pretty close to `iso 8601` there might be a predefined format for it. If not you could build it yourself with the `date` function. `date('Y-m-dTH:i:sZ'`. ISO example: http://stackoverflow.com/questions/903203/how-to-display-a-date-as-iso-8601-format-with-php – chris85 Dec 24 '16 at 13:20
  • Please find below link for PHP: http://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php – Jitendra Kumar. Balla Dec 24 '16 at 13:20
  • Is your time zone already UTC? – Álvaro González Dec 24 '16 at 14:24

2 Answers2

1

It looks like ISO 8601 format which can be achived by date with c param.

echo date('c', strtotime('2016-12-24 14:11:00'));

but if u want exactly that format you could personalize it

echo date('Y-m-d\TH:i:s\Z', strtotime('2016-12-24 14:11:00'));

If z letter means something then probably you need to find proper parameter on http://php.net/manual/en/function.date.php

Robert
  • 19,800
  • 5
  • 55
  • 85
0
SELECT concat(replace(`date_field`,' ','T'),'Z')
Roman Che
  • 137
  • 1
  • 7