cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Converting String into Snowflake Datetime

arvindnsn
Contributor

Hello,

 I need to insert the string " 30/01/2024 00:00 'DD/MM/YYYY HH24:MI' " into Snowflake Timestamp_NTZ(9) column as " 2024-01-30 00:00:00.000 'yyyy-MM-dd HH:mm:ss.SSS' ". I tried the following with no success. Any help would be appreciated.

1. Date.parse($var_date).toLocaleDateTimeString({"format":"yyyy-MM-dd HH:mm:ss.SSS"})

2. Date.parse($var_date, 'DD/MM/YYYY HH24:MI').toLocaleDateTimeString({"format":"yyyy-MM-dd HH:mm:ss.SSS"})

Tried the above and getting error.

Thanks

Aravind N

 

 

 

 

  

1 ACCEPTED SOLUTION

SpiroTaleski
Valued Contributor

@arvindnsn  

Probably the easiest way is to remove the part "DD/MM/YYYY HH24:MI" from the input string, parse it and converts it to a target date-time format. 

Date.parse("30/01/2024 00:00 'DD/MM/YYYY HH24:MI' ".substr(0,"30/01/2024 00:00 'DD/MM/YYYY HH24:MI' ".indexOf("'")).trim(),"dd/MM/yyyy HH:mm").toLocaleDateTimeString({"format":"yyyy-MM-dd HH:mm:ss.SSS"})

View solution in original post

2 REPLIES 2

SpiroTaleski
Valued Contributor

@arvindnsn  

Probably the easiest way is to remove the part "DD/MM/YYYY HH24:MI" from the input string, parse it and converts it to a target date-time format. 

Date.parse("30/01/2024 00:00 'DD/MM/YYYY HH24:MI' ".substr(0,"30/01/2024 00:00 'DD/MM/YYYY HH24:MI' ".indexOf("'")).trim(),"dd/MM/yyyy HH:mm").toLocaleDateTimeString({"format":"yyyy-MM-dd HH:mm:ss.SSS"})

That worked @SpiroTaleski !! Thanks for the solution.