Re: Interval to number

From: Brian McCane <bmccane(at)mccons(dot)net>
To: Gareth Kirwan <gbjk(at)thermeoneurope(dot)com>
Cc: <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Interval to number
Date: 2002-05-20 16:35:07
Message-ID: 20020520113223.I80087-100000@fw.mccons.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general pgsql-hackers pgsql-interfaces pgsql-odbc


EXTRACT is your friend :)

SELECT EXTRACT(EPOCH FROM max(occurrance) - min(occurrance))::integer ;

- brian

k=# SELECT EXTRACT(EPOCH FROM now() - '2001-01-01') ;
date_part
----------------
43583467.94995
(1 row)

On Mon, 20 May 2002, Gareth Kirwan wrote:

>
> Postgres 7.2
> I have an interval selected from a max(occurance) - min(occurance) where
> bla.
> I now want to multiply this by a rate - to create a charge...
>
> If I use to_char( interval, 'SSSS');
> I will get a seconds conversion - but that works on seconds since midnight -
> hence
> with a one day period.
>
> Are there any better ways of converting a timestamp to an integer?
>
>
> Thanks
>
> Gareth
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>

Wm. Brian McCane | Life is full of doors that won't open
Search http://recall.maxbaud.net/ | when you knock, equally spaced amid those
Usenet http://freenews.maxbaud.net/ | that open when you don't want them to.
Auction http://www.sellit-here.com/ | - Roger Zelazny "Blood of Amber"

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Gareth Kirwan 2002-05-20 16:40:46 Re: Interval to number
Previous Message Tom Lane 2002-05-20 15:14:35 Re: Access by 1000 users to view postgres tables without recreating accounts?

Browse pgsql-general by date

  From Date Subject
Next Message Patrick Welche 2002-05-20 16:36:30 Re: Row Locking
Previous Message Thomas Lockhart 2002-05-20 16:22:10 Re: On using "date 'XXX' + interval 'XXX'" vs "date 'XXX'"

Browse pgsql-hackers by date

  From Date Subject
Next Message Gareth Kirwan 2002-05-20 16:40:46 Re: Interval to number
Previous Message Thomas Lockhart 2002-05-20 16:16:44 Re: timestamp-to-date broken in current sources

Browse pgsql-interfaces by date

  From Date Subject
Next Message Gareth Kirwan 2002-05-20 16:40:46 Re: Interval to number
Previous Message Tom Lane 2002-05-20 16:01:41 Re: krb5 & multiple users

Browse pgsql-odbc by date

  From Date Subject
Next Message Gareth Kirwan 2002-05-20 16:40:46 Re: Interval to number
Previous Message Patrick Hatcher 2002-05-20 15:13:16 Re: int8 defined as text in MS Access?