SQL YEAR Function

SQL YEAR function is one of the Date and Time method, which will return an integer that represents the Year part of a specified date. The syntax of the YEAR method is


For this Year function in SQL Server example, we use the below-shown data

Employee Table for YEAR Function 1

SQL YEAR Function Example

In this example, we will show you the possible ways to use this Year

SELECT YEAR('07-19-1975') AS [Year Example 1]

SELECT YEAR('2015-11-24 12:29:44.513') AS [Year Example 2]

SQL YEAR Function 2

YEAR Function Example 2

We can achieve or get the Year number using the datepart as well. In this DateTime example, we are going to return the Year numbers from Hire Date in Employee table using the DATEPART, and the Year function.

      ,[FirstName] + ' '+ [LastName] AS [Full Name]
      ,YEAR([HireDate]) AS [Year Number]
      ,DATEPART(year, [HireDate]) AS [This Year From DatePart]
  FROM [Employee]

As you can see, both the SQL Server methods are returning the same result. Note, before 2012 people used the DATEPART to extract the Year but in 2012, Microsoft introduced the Year.

SQL YEAR Function 3

Comments are closed.