Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to Convert Array or String in Snowflake to Timestamp_NTZ

I currently have some incoming datestamps as from outside datasource, but am struggling to define them in a table through my Snowflake Tables.

The column is formatted as such: {"type":"TEXT","length":12,"byteLength":48,"nullable":true,"fixed":false}

The only current workaround I have is this convoluted code.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT timestamp_ntz_from_parts(
            GET(strtok_to_array(CONCAT('20',array_to_string(
                             regexp_substr_all('220530161501', '[[:digit:]][[:digit:]]', 1, 1),',')),','),0)::DOUBLE,
                               .......);

Any suggestions to convert string to integer for timestamp?

>Solution :

Assuming the format of input ‘YYMMDDHH24MISS’ and first 22 stands for 2022:

SELECT TRY_TO_TIMESTAMP_NTZ( '220530161501', 'YYMMDDHH24MISS');

Output:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading