SQL Server YEAR() Function

In SQL Server, the YEAR() function returns the year of the specified date as an integer.

YEAR(date)

Parameters

date: An expression that can resolve to a date, datetime, datetime2, time, smalldatetime, or datetimeoffset value. The date parameter can be a string literal, a user -defined variable, or a table column.

Return Value

Returns an integer that represents the year part of the specified date. It returns the same value as DATEPART(year, date).

If the specified date contains only the time part, then the YEAR() function returns 1900, the base year.

Get Year of DateTime

In the following example, date as a string literal is passed to the YEAR() function

Example: YEAR()
SELECT YEAR ('11/23/2022') AS Year

In the following example, the specified date parameter has just the time.

Example: YEAR()
SELECT YEAR ('10:22:15') AS Result

YEAR() with Column

In this example, the YEAR() function is used with the HireDate column of the Employee table and return the year of hiring employees.

Example: YEAR()
SELECT EmployeeID, FirstName, HireDate, YEAR (HireDate) AS YearHired FROM Employee