简体   繁体   中英

How do I convert character varying to timestamp in postgresql which is in the format [ “2020-09-21T13:56:58Z” ]

I tried doing this but got an error as:

ERROR: column "2020-09-21t13:56:58z" does not exits
Select to_timestamp("2020-09-21T13:56:58Z", "YYYY-MM-DDTHH24:MI:SSZ");

Try to_char() instead. As follows -

Sample data

create table a (
  date_time timestamp
  );
  
insert into a (date_time) values ('2020-09-21T13:56:58Z')

SELECT

select to_char(date_time, 'YYYY-MM-DDTHHH24:MI:SSZ') as time
from a

Result:

time
2020-09-21ST13:56:58Z

See db<>fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM