Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert text to timestamp in redshift

I have a text field "presence_changed_at" with text values i.e. '2014/12/17 08:05:28 +0000. I need to convert this into timestamp. In postgreSQL there is function TO_TIMESTAMP(), however in redshift this does not seem to be supported. I can get the date without time by

TO_DATE("presence_changed_at",'YYYY/MM/DD HH24:MI:SS')

which produces

2014-12-12

but i can't find any way to get TIMESTAMP format.

Thanks in advance for solving this

like image 888
user5157294 Avatar asked Jul 26 '15 11:07

user5157294


1 Answers

Below functions worked for me correctly... Use whichever is applicable for you...

cast(column_name as timestamp)

to_date(column_name,'MM/DD/YYYY HH24:MI:SS')

to_date(column_name,'MM/DD/YYYY HH12:MI:SS')

to_timestamp(column_name,'MM/DD/YYYY HH24:MI:SS')

like image 56
karthik G Avatar answered Sep 27 '22 20:09

karthik G