How to get year from date in sql server?

How to get year from date in sql server?

In this article you will learn how to get year from date in sql server, if you use SQL Server, you can use the YEAR() or DATEPART() function to extract the year from a date. For example, the following statement returns the current year in SQL Server: SELECT YEAR(CURRENT_TIMESTAMP); SELECT DATEPART(year, CURRENT_TIMESTAMP)

 

SQL Statement

 

SELECT YEAR('2021/01/04') AS Year;

OutPut

2021

 

SELECT strftime('%Y', CURRENT_TIMESTAMP)

 

the following statement returns the current year in SQL Server

 

SELECT DATEPART(year, CURRENT_TIMESTAMP);

SELECT YEAR(CURRENT_TIMESTAMP);

 

you pass the current date to the EXTRACT() function as follows:

 

SELECT EXTRACT(YEAR FROM CURRENT_DATE)

 

SELECT EXTRACT(YEAR FROM '2021-01-04')

2021-10-03