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?
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.
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.
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 ....
select year(current_timestamp)
SQLFiddle demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With