0

Using postgres, I am trying to convert minutes to a string consisting of two characters.

For example, if the code outputs 0, I want to convert this to '00'.

EXTRACT(TIMEZONE_MINUTE FROM CURRENT_TIMESTAMP)

I've tried this so far but it adds a space in front. So instead of getting '00' I get ' 00'

to_char(EXTRACT(TIMEZONE_MINUTE FROM CURRENT_TIMESTAMP), '00')

Any help would be super appreciated!

Mistakamikaze
  • 446
  • 3
  • 19

1 Answers1

1

Go straight to to_char with TZM(time-zone minutes):

 select to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC', 'TZM');
 to_char 
---------
 00

select length(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC', 'TZM'));
length 
--------
      2
(1 row)
Adrian Klaver
  • 15,886
  • 2
  • 17
  • 28