Recently, I was working on a requirement to extract the year from a date in SQL Server. After executing the SQL query, I got this error.
‘EXTRACT’ is not a recognized built-in function name.
I was executing the following query.
SELECT
sale_Date,
EXTRACT(YEAR FROM sale_Date) AS SalesYear
FROM
Sales
WHERE
EXTRACT(YEAR FROM sale_Date) BETWEEN 2020 AND 2025;After executing the above query, I got this error as shown in the screenshot below.

Solution
We can fix this error using the DATEPART function instead of the EXTRACT function using the query below.
SELECT
sale_Date,
DATEPART(YEAR, sale_Date) AS SalesYear
FROM
Sales
WHERE
DATEPART(YEAR, sale_Date) BETWEEN 2020 AND 2025;I got the expected output as shown in the screenshot below.

You may also like the following articles.
- The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
- Operand Type Clash: Date Is Incompatible With Int
- ‘to_date’ is not a recognized built-in function name.
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.