Re: Calculating with the time

From: Guy Fraser <guy(at)incentre(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Calculating with the time
Date: 2003-05-30 21:13:35
Message-ID: 3ED7C97F.7020805@incentre.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Is this what you are looking for?

test=# select 'now'::time as test,'2003-05-30 14:51:38-06'::timestamptz
as stamp into temp cruft;
SELECT
test=# select test,stamp,test - stamp::time as diff from cruft;
test | stamp | diff
-----------------+------------------------+-----------------
15:09:28.862728 | 2003-05-30 14:51:38-06 | 00:17:50.862728
(1 row)

test=# select test,stamp,reltime(test - stamp::time) as diff from cruft;
test | stamp | diff
-----------------+------------------------+----------
15:09:28.862728 | 2003-05-30 14:51:38-06 | 00:17:50
(1 row)

test=# drop table cruft;
DROP TABLE

Guy

Katka a Daniel Dunajsky wrote:

> Hello All,
>
> I am looking for an advice how to do calculation with the time. I do
> have a column with datatype 'timestamp with time zone'. The value is
> '2003-03-22 07:53:56-07' for instance. I would like to select it from
> the table with result of '07:59:59' – '07:53:56', so the query should
> return '00:06:03'.
>
> Thank you for your time.
>
> DanielD
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message jtx 2003-05-30 23:03:44 join/case
Previous Message Ian Barwick 2003-05-30 20:35:48 Re: Dynamic views/permissions