Skip to content
Advertisement

From HH:MI:SS to HH:MI in postgresql

I’m trying to do a query where the input is an hour in the HH24:MI:SS format, I want to return HH12:MI format, I tried the following:

select to_timestamp ('08:00:00', 'HH12:MI');

But it’s returning me this

0001-01-01 08:00:00-04:27:44 BC

How could I fix it?

Advertisement

Answer

You want to_char(), not to_timestamp():

select to_char('08:00:00'::time, 'HH12:MI');
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement