Skip site navigation (1) Skip section navigation (2)

How do you get the year from a postgresql DATE?

From: Mary Anderson <maryfran(at)demog(dot)berkeley(dot)edu>
To: pgsql-novice(at)postgresql(dot)org
Subject: How do you get the year from a postgresql DATE?
Date: 2009-10-23 23:59:28
Message-ID: 4AE24360.5080508@demog.berkeley.edu (view raw or flat)
Thread:
Lists: pgsql-novice
Hi guys,

    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;

and get 2000.

But I get a syntax error for the EXTRACT statement when I do this.

SELECT EXTRACT(YEAR FROM DATE '2000-01-01') works just fine.  But how do 
I get a postgres DATE from a column in a table into EXTRACT as the last 
argument?


This can't be all that hard!

Mary

Responses

pgsql-novice by date

Next:From: Stephan SzaboDate: 2009-10-24 00:06:24
Subject: Re: How do you get the year from a postgresql DATE?
Previous:From: richard terryDate: 2009-10-23 22:28:44
Subject: Re: creating view - conditional testing in construct

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group