Re: Determining period between 2 dates

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Thom Brown" <thom(at)linux(dot)com>, "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Determining period between 2 dates
Date: 2011-02-16 16:36:16
Message-ID: 4D5BA8A0020000250003AB17@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thom Brown <thom(at)linux(dot)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.

The SQL standard has syntax to support getting that in YEAR, MONTH,
DAY, HOUR, MINUTE, or SECOND (with the ability to specify decimal
positions for SECOND). Nothing in there about fortnights, however.

<left paren> <datetime value expression> <minus sign>
<datetime term> <right paren> <interval qualifier>

I seem to remember previous discussions where people have resisted
implementing this part of the standard, although I can't remember
the reason. I'll probably be reminded soon... :-)

-Kevin

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Marti Raudsepp 2011-02-16 17:07:13 Re: Determining period between 2 dates
Previous Message Simon Riggs 2011-02-16 16:32:21 Re: Sync Rep for 2011CF1