Thread: Calculating with the time

Calculating with the time

From
"Katka a Daniel Dunajsky"
Date:
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

_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.  
http://join.msn.com/?page=features/featuredemail



Re: Calculating with the time

From
Guy Fraser
Date:
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
>