timestampsnowflake-cloud-data-platform

Convert TZ format to timestamp in Snowflake


In Snowflake, I have dates in TZ format that I have to convert to regular timestamp without milliseconds. I did some operation, but the output turns out wrong.

Input:

2018-08-12T20:17:46.384Z

Desired Output:

2018-08-12 20:17:46

This is what I did on column ‘Time’.

TO_CHAR(Time::Timestamp yyyy-mm-dd hh:mm:ss)

This produces time in the mentioned format, however the values are wrong. I failed to identify what is the issue. Any help is appreciated.


Solution

  • Snowflake uses mm for month, mi for minutes. It's why you were seeing 08 for minutes since that's also your month. So just change what you have to this

    to_char('2018-08-12T20:17:46.384Z'::timestamp,'yyyy-mm-dd hh:mi:ss')