Re: Convert time to millisec?

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Bjørn T Johansen <btj(at)havleik(dot)no>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Convert time to millisec?
Date: 2006-08-28 13:20:02
Message-ID: 20060828132002.GA4250@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Aug 28, 2006 at 10:48:47AM +0200, Bjørn T Johansen wrote:
> select sum(Til - Fra) as total from Log_stop where OrdreID = 3434
>
> but I would like the result to be in milliseconds, is this possible? If so, how?
> (the fields Til and Fra is of type Time)

You could use extract(epoch from <interval>) to get the number of
seconds (with fractional part) in an interval, then multiply by
1000 to get milliseconds. Example:

select extract(epoch from sum(Til - Fra)) * 1000.0 ...

--
Michael Fuhr

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message macgillivary 2006-08-28 13:25:38 Re: speeding up big query lookup
Previous Message Rafal Pietrak 2006-08-28 13:19:24 Re: optimising UNION performance