Re: Format intervall as hours/minutes etc

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Format intervall as hours/minutes etc
Date: 2007-09-16 11:14:27
Message-ID: 20070916111427.GA13886@KanotixBox
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Andreas Joseph Krogh <andreak(at)officenet(dot)no> schrieb:

> Hi all. Any hint on how to format this interval as number of hour/seconds etc?
> select age('2007-09-22 17:00'::timestamp, '2000-02-20 18:00'::timestamp);
> age
> -------------------------------
> 7 years 7 mons 1 day 23:00:00

You can use extract(epoch, from ...) like this:

test=*# select extract(epoch from '2007-09-22 17:00'::timestamp) - extract (epoch from '2000-02-20 18:00'::timestamp);
?column?
-----------
239407200
(1 row)

Now you can calculate the hours and so on.

Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknow)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Joseph Krogh 2007-09-16 11:27:16 Re: Format intervall as hours/minutes etc
Previous Message Andreas Joseph Krogh 2007-09-16 11:00:53 Format intervall as hours/minutes etc