Thread: timespan casting

timespan casting

From
Jeff MacDonald
Date:
hi,

thought this up while playing with time spans..

here is my table and data..

bignose=> \d foo          Table "foo"Attribute |   Type    | Modifier 
-----------+-----------+----------start     | timestamp | stop      | timestamp | 

bignose=> select start,stop, stop-start as start_stop from foo;        start          |          stop          |
start_stop
 
------------------------+------------------------+------------2000-06-22 20:37:12-03 | 2000-06-22 20:37:12-03 |
00:0002000-06-2220:40:40-03 | 2000-06-23 20:40:40-03 | 1 00:002000-06-22 20:40:53-03 | 2000-09-30 20:40:53-03 | 100
00:002000-06-2220:41:08-03 | 2000-06-23 02:41:08-03 | 06:002000-06-22 20:41:30-03 | 2010-11-22 19:41:30-04 | 3805
00:00
(5 rows)

now my question.. first of all is the first start_stop result a little
off ? (talking about the 3 0's..)

second is there a way i can do a select so it says something more human
usable ie : 100 days 22 hours 32 minutes..

jeff





Re: timespan casting

From
Ed Loehr
Date:
Jeff MacDonald wrote:
> bignose=> select start,stop, stop-start as start_stop from foo;
>          start          |          stop          | start_stop
> ------------------------+------------------------+------------
>  2000-06-22 20:37:12-03 | 2000-06-22 20:37:12-03 | 00:000
> 
> now my question.. first of all is the first start_stop result a little
> off ? (talking about the 3 0's..)

What's off about it??  Your start and stop appear identical.

> second is there a way i can do a select so it says something more human
> usable ie : 100 days 22 hours 32 minutes..

Try to_char().  http://www.postgresql.org/docs/postgres/x2976.htm

Regards,
Ed Loehr