SQL query for extracting year from a date

John Doe picture John Doe · Nov 19, 2012 · Viewed 161.5k times · Source

I am trying to create a query that gets only the year from selected dates. I.e. select ASOFDATE from PSASOFDATE; returns 11/15/2012, but I want only 2012. How can I get only the year? I know the YEAR function can be used, but I'm not sure how.

Answer

Gee picture Gee · Jan 26, 2014

This worked for me:

SELECT EXTRACT(YEAR FROM ASOFDATE) FROM PSASOFDATE;