From: Michael Glaesemann <grzm@seespotcode.net>
To: Bryce Nesbitt <bryce1@obviously.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: extract or date_part on an interval? How many e
Date: Mon, 28 Jan 2008 00:19:04 -0500
Message-ID: <EA81A141-5E8B-4C82-8B9E-209817E62EC9@seespotcode.net> (raw)
In-Reply-To: <479D5F54.3040107@obviously.com>
References: <479D3E63.2080601@obviously.com>
<16843.1201489840@sss.pgh.pa.us>
<479D5F54.3040107@obviously.com>
On Jan 27, 2008, at 23:51 , Bryce Nesbitt wrote:
> Sigh. Ok, I settled on:
> select '1987-01-29'::timestamp + interval '21 years' > now();
> Which is closer to what I wanted anyway (this was all about
> determining who was under 21 years old). This at least should be
> robust over leap years.
I think this should work for you for your particular case:
EXTRACT(year FROM AGE(born_on)) >= 21
SELECT born_on, current_date, age(born_on), EXTRACT(year FROM AGE
(born_on)) AS age_in_years, EXTRACT(year FROM age(born_on)) >= 21 as
old_enough_to_drink FROM (SELECT CAST('1987-01-25' AS DATE) + i AS
born_on FROM generate_series(0,5) as the(i)) foo;
born_on | date | age | age_in_years |
old_enough_to_drink
------------+------------+--------------------------+--------------
+---------------------
1987-01-25 | 2008-01-28 | 21 years 3 days | 21 | t
1987-01-26 | 2008-01-28 | 21 years 2 days | 21 | t
1987-01-27 | 2008-01-28 | 21 years 1 day | 21 | t
1987-01-28 | 2008-01-28 | 21 years | 21 | t
1987-01-29 | 2008-01-28 | 20 years 11 mons 30 days | 20 | f
1987-01-30 | 2008-01-28 | 20 years 11 mons 29 days | 20 | f
(6 rows)
Michael Glaesemann
grzm seespotcode net
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: grzm@seespotcode.net, bryce1@obviously.com
Subject: Re: extract or date_part on an interval? How many e
In-Reply-To: <EA81A141-5E8B-4C82-8B9E-209817E62EC9@seespotcode.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox