to_timesamp converting month to different month

36 Views Asked by At

Any idea why snowflake to_timestamp is converting February month to January?

    SELECT to_timestamp(to_char('2022-02-02 08:01:29 AM'),'YYYY-MM-DD HH12:MM:SS AM');
    -- 2022-01-02 08:00:29.000
1

There are 1 best solutions below

0
eshirvana On BEST ANSWER

MM represent month when you convert to char , you should use MI for minute in snowflake, I assume the issue comes from there :

SELECT to_timestamp(to_char('2022-02-02 08:01:29 AM','YYYY-MM-DD HH12:MI:SS AM'));