how to extract only the year from the date in sql server 2008?

Praveen picture Praveen · Sep 15, 2012 · Viewed 438.1k times · Source

In sql server 2008, how to extract only the year from the date. In DB I have a column for date, from that I need to extract the year. Is there any function for that?

Answer

Dumitrescu Bogdan picture Dumitrescu Bogdan · Sep 15, 2012
year(@date)
year(getdate())
year('20120101')

update table
set column = year(date_column)
whre ....

or if you need it in another table

 update t
   set column = year(t1.date_column)
     from table_source t1
     join table_target t on (join condition)
    where ....