Padding time values from EXTRACT()

From: Mark Kelly <pgsql(at)wastedtimes(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Padding time values from EXTRACT()
Date: 2009-11-19 00:15:38
Message-ID: 200911190015.38074.pgsql@wastedtimes.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi.

If I use the following snippet

EXTRACT (hour FROM timestamp) || ':' ||
EXTRACT (minute FROM timestamp)
AS this_time

I get single digit figures returned for minutes less than 10, resulting in the
odd-looking 12:5 when I was expecting 12:05.

Actual column value is '2009-11-18 12:05:31.030546', which I why I assumed I'd
get the 0 in the returned value.

Is there any way to zero pad the only the values below 10 so I always get two
character responses for the minutes?

Thanks,

Mark

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2009-11-19 00:37:23 Re: Padding time values from EXTRACT()
Previous Message Richard Broersma 2009-11-18 20:33:08 Re: Introduction