Re: Determining period between 2 dates - Mailing list pgsql-hackers

From Marti Raudsepp
Subject Re: Determining period between 2 dates
Date
Msg-id AANLkTi=c4VB38DkyiC4VQfA9Ak+Gyy+EJNOe1eHjOFg-@mail.gmail.com
Whole thread Raw
In response to Re: Determining period between 2 dates  (Thom Brown <thom@linux.com>)
Responses Re: Determining period between 2 dates
List pgsql-hackers
On Wed, Feb 16, 2011 at 18:03, Thom Brown <thom@linux.com> wrote:
> For the number of fortnights, that becomes:
>
> select extract(epoch from now() - '2010-01-01 11:45:13'::timestamp)/60/60/24/14;
>
> You'd think with PostgreSQL having such a rich type system, it
> wouldn't need to come to that.  It's just asking for the number of
> intervals between 2 timestamps rather than the number of seconds and
> dividing it to the point you get your answer.

I think a good generic solution would be an interval/interval operator
that returns numeric. Then the above becomes:

SELECT (now() - timestamp '2010-01-01 11:45:13') / interval '2 weeks';

However, looking at the code, it's not so obvious what to do if the
intervals contain months.

Regards,
Marti


pgsql-hackers by date:

Previous
From: "Kevin Grittner"
Date:
Subject: Re: Determining period between 2 dates
Next
From: Tim Bunce
Date:
Subject: Re: arrays as pl/perl input arguments [PATCH]