Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format datetime column to ISO date-time in Redshift

I'm trying to convert datetime column to ISO datetime format without any success.

The only correct result I managed to get is by doing this sql:

select TO_CHAR(getdate(), 'YYYY-MM-DD')||'T'||TO_CHAR(getdate(),'HH24:MI:SS')

but I'm sure there is a more adequate method to achieve this.

Just to make sure I'm clear enough, I'm trying to get this format: 2011-12-03T10:15:30

P.S.

I tried the trivial sql and it doesn't work ==>

SELECT TO_CHAR(getdate(), 'YYYY-MM-DDTHH24:MI:SS');

gives this result:

2017-02-19THH24:38:46

and of course I wanted it differently: 2017-02-19T10:38:46

like image 451
Ziv Gabovitch Avatar asked Dec 15 '22 00:12

Ziv Gabovitch


1 Answers

OK, I managed to achieve this with the mix of ' and " ==>

SELECT TO_CHAR(getdate(), 'YYYY-MM-DD"T"HH24:MI:SS');

gives the result of: 2017-02-19T16:00:40

EDIT: I found a simpler solution:

SELECT TO_CHAR(getdate(), 'YYYY-MM-DDThh24:MI:SS');

It appears that the upper HH made a problem. Once converted to hh it worked

like image 110
Ziv Gabovitch Avatar answered Dec 24 '22 09:12

Ziv Gabovitch