In this comprehensive article, I’ll explain multiple approaches to extracting the year from dates in SQL Server, with examples and best practices. By the end of this tutorial, you’ll have a clear picture of this.
SQL Server Extract Year From Date
Now, let’s explore the different methods for extracting the year from a date in SQL Server.
Approach 1: Using the YEAR() Function
The most straightforward approach to extracting the year from a date in SQL Server is to use the built-in YEAR() function. This function takes a date expression as input and returns an integer representing the year.
Syntax
YEAR(date_expression)
Example
SELECT YEAR(GETDATE()) AS CurrentYear;After executing the above query, I got the expected output as shown in the screenshot below.

Using the query below, you can also use the YEAR() function with date columns in your tables.
SELECT
sale_Date,
YEAR(sale_Date) AS SalesYear
FROM
Sales
WHERE
YEAR(sale_Date) = 2025;I got the expected output after executing the above query as shown in the screenshot below.

Approach 2: Using DATEPART() Function
Another common approach is to use the DATEPART() function.
Syntax
DATEPART(YEAR, date_expression)Example
SELECT
sale_Date,
DATEPART(YEAR, sale_Date) AS SalesYear
FROM
Sales
ORDER BY
SalesYear;After executing the above query, I got the expected output as shown in the screenshot below.

The DATEPART function is more versatile than YEAR() because it can extract other date components like month, day, quarter, etc., using the same syntax pattern.
Approach 3: Using CONVERT or CAST with Style Codes
For more control over date formatting, you can use the CONVERT function with style codes to extract the year component.
Syntax
CONVERT(CHAR(4), date_expression, 112)Example
SELECT
sale_Date,
LEFT(CONVERT(VARCHAR, sale_Date, 112), 4) AS SalesYear
FROM
Sales;This method converts the date to a string in YYYYMMDD (style code 112), then extracts the first four characters (the year). I got the same output as shown in the screenshot below.

Performance Considerations
When working with large datasets, your method for extracting years can impact query performance.
- YEAR() function is generally the most efficient for simple year extraction
- DATEPART() has similar performance to YEAR()
- String conversion methods (CONVERT, CAST) are typically less efficient
Benchmark Comparison
| Method | Execution Time (ms) | Relative Performance |
|---|---|---|
| YEAR() | 320 | Fastest |
| DATEPART(YEAR, date) | 325 | Nearly identical |
| String conversion | 450 | ~40% slower |
Best Practices
- Use the proper function for the job: YEAR() for simple extraction, DATEPART() when you need multiple date components.
- Consider index usage: Avoid wrapping indexed columns in functions when filtering.
- Be mindful of data types: When storing extracted years, use INT or SMALLINT data types.
- Beware of NULL dates: Always handle NULL values appropriately
- Use parameterized queries: When extracting years for comparison with user input
Conclusion
Extracting the year from dates in SQL Server is an essential skill. Whether you use the YEAR() function, DATEPART(), or other approaches as explained in this article depends on your specific requirements and performance considerations.
You may also like the following articles.
- SQL Server Get Month From Date
- SQL Server Insert Date
- ‘EXTRACT’ is not a recognized built-in function name.
- SQL Server Filter By Date
After working for more than 15 years in the Software field, especially in Microsoft technologies, I have decided to share my expert knowledge of SQL Server. Check out all the SQL Server and related database tutorials I have shared here. Most of the readers are from countries like the United States of America, the United Kingdom, New Zealand, Australia, Canada, etc. I am also a Microsoft MVP. Check out more here.