Skip to content
Related Articles

Related Articles

Improve Article

YEAR() Function in SQL Server

  • Last Updated : 11 Jan, 2021

YEAR() function :
This function in SQL Server is used to return the year for a date stated.

Features :

  • This function is used to find the year for a date specified.
  • This function comes under Date Functions.
  • This function accepts only one parameter i.e, date.
  • This function can also include time with the stated date.

Syntax :

YEAR(date)

Parameter :
This method accepts only one parameter as given below :

  • date : Specified date from which the year is to be returned.

Returns :
It returns the year for a date specified.



Example-1 :
Using YEAR() function and getting the year from the date specified.

SELECT YEAR('2020/01/02');

Output :

2020

Example-2 :
Using YEAR() function with a variable and getting the year from the date specified.

DECLARE @date VARCHAR(50);
SET @date = '2017/07/05';
SELECT YEAR(@date);

Output :

2017

Example-3 :
Using YEAR() function with date as parameter which includes time as well.

SELECT YEAR('2018/11/22 07:44');

Output :

2018

Example-4 :
Using YEAR() function with a variable and a date as parameter which includes time as well.

DECLARE @date VARCHAR(50);
SET @date = '1995/05/13 23:59';
SELECT YEAR(@date);

Output :

1995

Application :
This function is used to find the year from a date specified.

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

My Personal Notes arrow_drop_up
Recommended Articles
Page :