Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 516
Praveen Avatar asked Sep 15 '12 10:09

Praveen


People also ask

How do I select just the year from a date?

Display only year If you want to enter a date and only display the year, you can apply a custom number format like "yyyy" or "yy". The MONTH function takes just one argument, the date from which to extract the month. In the example shown, the formula is: = MONTH ( B4 ) where B4 contains the dateJanuary 5, 2016.

How do I select a specific year in SQL?

Use SQL Server's YEAR() function if you want to get the year part from a date. This function takes only one argument – a date, in one of the date and time or date data types. (In our example, the column BirthDate is a date data type). The argument can be a column name or an expression.


2 Answers

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 .... 
like image 113
Dumitrescu Bogdan Avatar answered Oct 21 '22 08:10

Dumitrescu Bogdan


select year(current_timestamp) 

SQLFiddle demo

like image 43
juergen d Avatar answered Oct 21 '22 09:10

juergen d