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

If the post helped you, please share it:
Pin It

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

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">