Formatting a date as ISO-8601 in PostgreSQL


The magic string is 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'.

SELECT
    NOW(),
    TO_CHAR (NOW() at time zone 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"')

Hack way using TO_JSON:

SELECT to_json(now())#>>'{}'

source

Tags:  postgresql  iso8601

Share: