Re: How do you get the year from a postgresql DATE? - Mailing list pgsql-novice

From ...tharas
Subject Re: How do you get the year from a postgresql DATE?
Date
Msg-id 82d9696a0910231733g1d4a457ah14b6d54d617c866e@mail.gmail.com
Whole thread Raw
In response to Re: How do you get the year from a postgresql DATE?  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Responses Re: How do you get the year from a postgresql DATE?  (Brian Modra <brian@zwartberg.com>)
List pgsql-novice
Hello,

If column fu is of data type DATE, you could use
 SELECT EXTRACT(YEAR FROM fu) FROM mydate;
and if it is varchar, you convert it to date using to_date()
 SELECT EXTRACT(YEAR FROM to_date(fu, <your pattern>)) FROM mydate;

Regards.

Thara


On Sat, Oct 24, 2009 at 5:36 AM, Stephan Szabo <sszabo@megazone.bigpanda.com> wrote:
On Fri, 23 Oct 2009, Mary Anderson wrote:

>     Honest, I am not really a newbie, but I don't see any postgresql
> function to do this in the documentation.  I want to do something like
>
> CREATE TABLE mydate(fu DATE);
> INSERT INTO mydate VALUES ('2000-01-01');
> SELECT EXTRACT(YEAR FROM DATE fu) FROM mydate;

I think you'd just want something like:
 SELECT EXTRACT(YEAR FROM fu) FROM mydate;

DATE '2000-01-01' is a syntax for providing a date literal, not treating
an expression as a date.

--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice



--
.regards
.thara s pillai

pgsql-novice by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: How do you get the year from a postgresql DATE?
Next
From: Brian Modra
Date:
Subject: Re: How do you get the year from a postgresql DATE?