Search code examples
datevertica

How to handle DD/MM date time string in Vertica TO_TIMESTAMPTZ?


I have some date time strings with day first. When I try to convert to TIMESTAMPTZ the month seems to be ignored. Example

TO_TIMESTAMPTZ('01/07/2020 04:00', 'DD/MM/YYYY HH:MM')

Returns

2020-01-01T04:00:00.000+00:00

I'm looking for 1st July but get 1st January (not even 7th January!)


Solution

  • The pattern for minutes is MI, not MM (see documentation):

    dbadmin=> select TO_TIMESTAMP_TZ('01/07/2020 04:00', 'DD/MM/YYYY HH:MI');
        TO_TIMESTAMP_TZ
    ------------------------
     2020-07-01 04:00:00+02