Getting interval in seconds?

Поиск
Список
Период
Сортировка
Искать

Getting interval in seconds?

От:
Lincoln Yeoh <lyeoh@pop.jaring.my>
Дата:
Hi,

How do I convert an interval to the number of seconds?

e.g. I'd like the following to produce a result in seconds.

select ('now'::timestamp - somedate)::interval from sometable;

Thanks,
Link.

Re: Getting interval in seconds?

От:
Alex Pilosov <alex@pilosoft.com>
Дата:
On Sun, 10 Jun 2001, Lincoln Yeoh wrote:

> Hi,
> 
> How do I convert an interval to the number of seconds?
> 
> e.g. I'd like the following to produce a result in seconds.
> 
> select ('now'::timestamp - somedate)::interval from sometable;

select date_part('epoch',('now'::timestamp - somedate)::interval) from
sometable;

-alex

Re: Getting interval in seconds?

От:
Lincoln Yeoh <lyeoh@pop.jaring.my>
Дата:
Thanks!

Which is better/faster?

select date_part('epoch',('now'::timestamp - somedate)::interval) from
sometable;

Or

select extract (epoch from interval ('now'::timestamp - somedate)) from
sometable;

Should I be using 'now'::timestamp or some function form of it?

Cheerio,
Link.

At 10:34 PM 10-06-2001 -0400, Alex Pilosov wrote:
>On Sun, 10 Jun 2001, Lincoln Yeoh wrote:
>
>> Hi,
>> 
>> How do I convert an interval to the number of seconds?
>> 
>> e.g. I'd like the following to produce a result in seconds.
>> 
>> select ('now'::timestamp - somedate)::interval from sometable;
>
>select date_part('epoch',('now'::timestamp - somedate)::interval) from
>sometable;
>
>-alex
>
>
>

Re: Getting interval in seconds?

От:
Alex Pilosov <alex@pilosoft.com>
Дата:
On Sun, 10 Jun 2001, Lincoln Yeoh wrote:

> Thanks!
> 
> Which is better/faster?
> 
> select date_part('epoch',('now'::timestamp - somedate)::interval) from
> sometable;
> 
> Or
> 
> select extract (epoch from interval ('now'::timestamp - somedate)) from
> sometable;
Speedwise, I think its the same. _maybe_ the latter is faster, but I
wouldn't bet on it.

> Should I be using 'now'::timestamp or some function form of it?
No difference whether you use now() or 'now'::timestamp.

-alex


FAQ