Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
Thread:
Lists: pgsql-adminpgsql-generalpgsql-hackerspgsql-interfacespgsql-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

pgsql-odbc by date

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

pgsql-hackers by date

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

pgsql-admin by date

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

pgsql-interfaces by date

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

pgsql-general by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group