Re: fomatting an interval (resend) - Mailing list pgsql-general

From Joseph Shraibman
Subject Re: fomatting an interval (resend)
Date
Msg-id 3EC04E94.9060506@selectacast.net
Whole thread Raw
Responses Re: fomatting an interval (resend)
List pgsql-general
Tom Lane wrote:

 >>>> How can I format an interval?
 >
 >
 >
 > Well, there are several possibilities such as to_char() and EXTRACT()
 > ...
 >
Right, except I don't know what format to use for to_char()

 >
 >> I want something like the default format but without the milliseconds.
 >
 >
 >
 > ... but for this particular problem, why not just round the given
 > interval to an integral number of seconds, by casting it to interval(0)?
 >

playpen=# select version();
                                version
---------------------------------------------------------------------
  PostgreSQL 7.3.2 on i686-pc-linux-gnu, compiled by GCC egcs-2.91.66
(1 row)

playpen=# begin;
BEGIN
playpen=# create table timetable (start timestamp, finish timestamp);
CREATE TABLE
playpen=# insert into timetable values('2003-05-12 21:37:44.933',  '2003-05-12 21:39:14.752');
INSERT 1648889 1
playpen=# select start, finish, (finish-start),(finish-start)::interval(0) from timetable;
           start          |         finish          |   ?column?   |   interval
-------------------------+-------------------------+--------------+--------------
  2003-05-12 21:37:44.933 | 2003-05-12 21:39:14.752 | 00:01:29.819 | 00:01:29.819
(1 row)

Tom Lane wrote:
>>>>How can I format an interval?
>
>
> Well, there are several possibilities such as to_char() and EXTRACT()
> ...
>
Right, except I don't know what format to use for to_char()

>
>>I want something like the default format but without the milliseconds.
>
>
> ... but for this particular problem, why not just round the given
> interval to an integral number of seconds, by casting it to interval(0)?
>

playpen=# select version();
                                version
---------------------------------------------------------------------
  PostgreSQL 7.3.2 on i686-pc-linux-gnu, compiled by GCC egcs-2.91.66
(1 row)

playpen=# begin;
BEGIN
playpen=# create table timetable (start timestamp, finish timestamp);
CREATE TABLE
playpen=# insert into timetable values('2003-05-12 21:37:44.933',  '2003-05-12 21:39:14.752');
INSERT 1648889 1
playpen=# select start, finish, (finish-start),(finish-start)::interval(0) from timetable;
           start          |         finish          |   ?column?   |   interval
-------------------------+-------------------------+--------------+--------------
  2003-05-12 21:37:44.933 | 2003-05-12 21:39:14.752 | 00:01:29.819 | 00:01:29.819
(1 row)



pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: fomatting an interval
Next
From: Tom Lane
Date:
Subject: Re: fomatting an interval