Postgresql to_char add characters to date

1366 views sql
3

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:

2018-11-01STH24:17:35Z 

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

1

This is too long for a comment.

When I run:

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

I get:

2018-11-04THH24:55:39Z

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?

JD

Please login first before posting an answer.

Ads

Categories