Re: BUG #3260: Subtracting intervals - Mailing list pgsql-bugs

From Alvaro Herrera
Subject Re: BUG #3260: Subtracting intervals
Date
Msg-id 20070503171546.GH4218@alvh.no-ip.org
Whole thread Raw
In response to BUG #3260: Subtracting intervals  ("Dhugael McLean" <box@yourtechonline.com>)
List pgsql-bugs
Dhugael McLean wrote:

> select '1 day'::interval - '55 minutes'::interval;
>
>     ?column?
> -----------------
>  1 day -00:55:00
>
> If the interval periods are both minutes (hours - hours, days - days, etc),
> this works fine. Days - minutes seems to fail. This should output 23:05:00.

No, that answer would be wrong because not all days are 24 hours long
(think DST).  You can use justify_hours() if you want to make that
assumption:

alvherre=# select justify_hours('1 day'::interval - '55 minutes'::interval);
 justify_hours
---------------
 23:05:00
(1 fila)

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #3260: Subtracting intervals
Next
From: "Jose Blanco"
Date:
Subject: order by question.