Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL query for extracting year from a date

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.

like image 402
John Doe Avatar asked Nov 19 '12 14:11

John Doe


2 Answers

This worked for me:

SELECT EXTRACT(YEAR FROM ASOFDATE) FROM PSASOFDATE;
like image 53
Gee Avatar answered Oct 27 '22 19:10

Gee


SELECT date_column_name FROM table_name WHERE EXTRACT(YEAR FROM date_column_name) = 2020

like image 20
Siddharth Sonwane Avatar answered Oct 27 '22 19:10

Siddharth Sonwane