Is there a builtin function for formatting time values?

Started by Frank Churchabout 16 years ago2 messagesgeneral
Jump to latest
#1Frank Church
voipfc@googlemail.com

I have to this to extract formated times from timestamps, but I
suspect there is something much better, even if it uses a stored
procedure. The lpad command to is also funny because I have to
concatenate it with an empty quote to convert the output to a string.

select lpad(extract(hour from calldate) || '', 2, '0') || ':' ||
lpad(extract(minute from calldate) || '', 2, '0') || ':' ||
lpad(extract(second from calldate) || '', 2, '0') from asterisk_cdr

There must be a formattted into to string function or a formatted time
function somewhere.

Are there any links to PostgreSQL stored procedure libraries?

/voipfc

#2Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Frank Church (#1)
Re: Is there a builtin function for formatting time values?

On Thursday 28 January 2010 2:23:26 pm Frank Church wrote:

I have to this to extract formated times from timestamps, but I
suspect there is something much better, even if it uses a stored
procedure. The lpad command to is also funny because I have to
concatenate it with an empty quote to convert the output to a string.

select lpad(extract(hour from calldate) || '', 2, '0') || ':' ||
lpad(extract(minute from calldate) || '', 2, '0') || ':' ||
lpad(extract(second from calldate) || '', 2, '0') from asterisk_cdr

There must be a formattted into to string function or a formatted time
function somewhere.

Are there any links to PostgreSQL stored procedure libraries?

/voipfc

http://www.postgresql.org/docs/8.4/interactive/functions-formatting.html
http://www.postgresql.org/docs/8.4/interactive/functions-datetime.html

--
Adrian Klaver
adrian.klaver@gmail.com