sqlpostgresqliso8601to-char

Convert date to YYYY-MM-DDThh:mm:ss.sssZ format in Postgresql


I want to convert the date format to YYYY-MM-DDThh:mm:ss.SSSXXXZ (ISO 8601).

Getting 2021-02-10T04:02:55.55SXXXZ and it's wrong. I need it as 2021-02-10T04:02:55.55S000000Z.

select to_char(now(), 'YYYY-MM-DDThh:mm:ss.SSSXXXZ')

Solution

  • For ISO 8601 date format you can use below query:

    select to_char(now(), 'YYYY-MM-DD"T"HH24:MI:SS"Z"')
    

    Output: "2021-02-10T12:09:17Z"

    Is it your desired format?