'How to select only year from datetimestamp

I want to populate my table's column with only year from datetimestamp.

I am using the below query:

date_format(df.startyear,'yyy') as startyear,

But this is returning null values. Can anyone please help?

sql


Solution 1:[1]

Given your initial attempt to use DATE_FORMAT, I suspect you're using MySQL. If accurate you can retrieve the YEAR in a couple of ways.

Using YEAR

YEAR(df.startyear) AS startyear

Using EXTRACT

EXTRACT(YEAR FROM df.startyear) AS startyear

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1