YEAR function is used to get year part from the specified date.
Syntax of YEAR Function :
YEAR(date)
date is an expression of datetime or smalldatetime type.
It returns an integer value.
Examples of YEAR Function :
Example 1 : Use of YEAR function in select clause
SELECT YEAR('05/31/2000')
Output
2000
Above example returns year of specified date in a string format.
Example 2 : Use of YEAR function in where clause
SELECT ShipName, OrderDate
FROM Orders
WHERE YEAR('05/31/1998') = YEAR(OrderDate)
Output
ShipName OrderDate
Lehmanns Marktstand 1998-01-30 00:00:00.000
HILARION-Abastos 1998-02-02 00:00:00.000
Above example displays all orders having year 1998.