Listing Past Year, Present Year and Next Year Information in SQL Server

Hello to everyone,

In this article, I will provide information about listing past year, current year and next year information in SQL Server.

In SQL Server, in some cases, you may want to list information for the past year, current year, and next year.

You can easily do this using the code below.

SELECT DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0) AS [Current Year],
       DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, -1) AS [Last Day of Current Year ],
       DATEADD(ms, -3, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, 0)) AS [Last Time of Current Year],
       DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, 0) AS [Next Year],
       DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 2, -1) AS [Last Day of Next Year],
       DATEADD(ms, -3, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 2, 0)) AS [Last Time of Next Year],
       DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) - 1, 0) AS [Past Year],
       DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), -1) AS [Last Day of Past Year],
       DATEADD(ms, -3, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)) AS [Last Time of Past Year];

When you run the above code, you will see a result similar to the one below.

Listing Past Year Present Year and Next Year Information in SQL Server

As can be seen, information for the past year, current year and next year has been listed.

Good luck to everyone in business and life.

270 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!