Postgresql to_char add characters to date

1378 views sql

I want to select dates with this format: 2018-11-25T16:00:00Z

So i tried to do this:

select to_char(registration_date, 'YYYY-MM-DDTHH24:MI:SSZ')
from ...

but its output is:


The char 'T' changes the date output instead of just print it in the middle. I tried to add space next to the char 'T' like this :

select to_char(registration_date, 'YYYY-MM-DDT HH24:MI:SSZ')

and it works, but i need the date without spaces.

How can I add the char 'T' to the middle of the date, and the output will be the same as the first example?

answered question

1 Answer


This is too long for a comment.

When I run:

select to_char(now(), 'YYYY-MM-DDTHH24:MI:SSZ')

I get:


You can run this yourself on rextester.

I don't know where the "S" is coming from. It is not coming from to_char().

posted this

Have an answer?


Please login first before posting an answer.