How to Get First and Last Day of a Year in SQL Server

To get the first day of the previous year in SQL Server, use the following code:

SELECT DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) - 1, 0)

first_day_of_last_year

To get the last day of the previous year:

SELECT DATEADD(dd, -1, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0))

last_day_of_last_year

To get the first day of the current year:

SELECT DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)

first_day_of_current_year

To get the last day of the current year:

SELECT DATEADD (dd, -1, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) +1, 0))

last_day_of_current_year

To get the first day of the next year:

SELECT DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, 0)

first_day_of_next_year

To get the last day of the next year:

SELECT DATEADD (dd, -1, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) +2, 0))

last_day_of_next_year