如何从sql server 2008中的日期中仅提取年份?

Pra*_*een 71 sql datetime extract sql-server-2008

在sql server 2008中,如何仅从日期中提取年份.在DB中我有一个日期列,从中我需要提取年份.那有什么功能吗?

Dum*_*dan 111

year(@date)
year(getdate())
year('20120101')

update table
set column = year(date_column)
whre ....
Run Code Online (Sandbox Code Playgroud)

或者如果你需要在另一张桌子里

 update t
   set column = year(t1.date_column)
     from table_source t1
     join table_target t on (join condition)
    where ....
Run Code Online (Sandbox Code Playgroud)


her*_*arn 12

您可以使用year()sql中的函数从指定日期获取年份.

句法:

YEAR ( date )
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请点击此处


小智 5

year(table_column)
Run Code Online (Sandbox Code Playgroud)

例:

select * from mytable where year(transaction_day)='2013' 
Run Code Online (Sandbox Code Playgroud)