Re: [GENERAL] timespan

From: Ulf Mehlig <umehlig(at)uni-bremen(dot)de>
To: bobd(at)palaver(dot)net
Cc: pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] timespan
Date: 1998-11-06 08:35:05
Message-ID: 199811060835.JAA02030@uni-bremen.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bob Dusek <bobd(at)palaver(dot)net> wrote:

> does anyone know how to take a value of type timespan and convert it
> into a single float8 or int value?

I don't know whether this will help:

=> select date_part ('epoch', age('29.02.2000'::date,
'29.02.1968'::date)) as days;

will give you the seconds elapsed over the timespan given by
age(). Used with an absolute date, it will give you the number of
seconds since the Unix epoch (negative for dates before 01.01.1970,
positive after). You can divide the resulting number by others, so

=> select date_part ('epoch', age('29.02.2000'::date,
'29.02.1968'::date)) /
(60*60*24)
as days;

days
-----
11688
(1 row)

gives you the number of days in the interval. If you use
datetime-values, a float value can be obtained:

=> select date_part ('epoch', age('29.02.2000'::date,
datetime('29.02.1968','11:33'))) /
(60*60*24)
as days;

days
-----------
11681.26875
(1 row)

In the case of timespans, 'epoch' as date_part() specifier might be
misleading ... Couldn't it be aliased to something like
'elapsed_secs'?

Bye,
Ulf

--
======================================================================
%%%%% Ulf Mehlig <ulf(dot)mehlig(at)uni-bremen(dot)de>
%%%%!%%% Projekt "MADAM" <umehlig(at)uni-bremen(dot)de>
%%%% %!% %%%% ----------------------------------------------------
---| %%% MADAM: MAngrove | Center for Tropical Marine
||--%!% Dynamics | Biology
|| And | Fahrenheitstrasse 1
_ /||\_/\_ Management |
/ / \ \ ~~~~~~~~~~~~~~~~~ | 28359 Bremen/Germany
~~~~~~~~~~~~~~~~~~~~

In response to

  • timespan at 1998-11-06 02:49:49 from Bob Dusek

Responses

Browse pgsql-general by date

  From Date Subject
Next Message A James Lewis 1998-11-06 08:55:17 Re: [GENERAL] timespan
Previous Message The Hermit Hacker 1998-11-06 03:11:56 Re: [GENERAL] Upcoming 6.4 release issues - WinNT