Re: fomatting an interval (resend)

Greg Sabino Mullane <greg@turnstep.com>

From: greg@turnstep.com
To: pgsql-general@postgresql.org
Date: 2003-05-30T18:37:06Z
Lists: pgsql-hackers
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>>> Okay, so extract() doesn't fit the bill either.  How do I get the
>>> difference between two timestamps in terms of days, expressed as an
>>> integer?  Moreover, how do I get any interval expressed in those
>>> terms?

>> select round((extract(epoch from finish) - 
>> extract(epoch from start))/(60*60*24)) from timetable;

>How would that differ from the query below?
>
>select round(extract(epoch from (finish - start))/(60*60*24)) from 
>timetable;

No real difference - the first is extracting from timestamps, the 
second is extracting from an interval. The second is more compact, 
but I prefer the first as it is a little more explicit in what is 
happening.

- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200305301433
-----BEGIN PGP SIGNATURE-----
Comment: http://www.turnstep.com/pgp.html

iD8DBQE+16QZvJuQZxSWSsgRAhPyAKC9lz5pAr7W94Sm6MPXp77CoG04UgCg062W
0ylMMu/79liaR48hG3tIw2c=
=zQTl
-----END PGP SIGNATURE-----