Re: [GENERAL] timespan

Поиск
Список
Период
Сортировка
От Ulf Mehlig
Тема Re: [GENERAL] timespan
Дата
Msg-id 199811060835.JAA02030@uni-bremen.de
обсуждение исходный текст
Ответ на timespan  (Bob Dusek <bobd@palaver.net>)
Ответы Re: [GENERAL] timespan  (Ulf Mehlig <umehlig@uni-bremen.de>)
Список pgsql-general
Bob Dusek <bobd@palaver.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.mehlig@uni-bremen.de>
   %%%%!%%%       Projekt "MADAM"         <umehlig@uni-bremen.de>
%%%% %!% %%%%     ----------------------------------------------------
 ---| %%%         MADAM:  MAngrove    |  Center for Tropical Marine
    ||--%!%              Dynamics     |  Biology
    ||                  And           |  Fahrenheitstrasse 1
 _ /||\_/\_            Management     |
/  /    \  \ ~~~~~~~~~~~~~~~~~        |  28359 Bremen/Germany
  ~~~~~~~~~~~~~~~~~~~~

В списке pgsql-general по дате отправления:

Предыдущее
От: The Hermit Hacker
Дата:
Сообщение: Re: [GENERAL] Upcoming 6.4 release issues - WinNT
Следующее
От: A James Lewis
Дата:
Сообщение: Re: [GENERAL] timespan