Equivalent of Oracle LAST_DAY Function in SQL Server

Hello everyone,

In this article, I will give information about the equivalent of the Oracle LAST_DAY() function in SQL Server.

In SQL Server, in some cases, we may want to see and use functions that are in other databases.

What is the LAST_DAY() function?

The LAST_DAY() function returns the date of the last day of the month containing the date. The return type is always DATE, regardless of the date’s data type.

You can easily do this with the help of the code below.

DECLARE @Tarih DATETIME
SELECT @Tarih = GETDATE()
SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, @Tarih) + 1, 0) - 1

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

Equivalent of Oracle LAST DAY Function in SQL Server

 

As you can see, we have returned the last day of the month as a date by using the date information.

Good luck to everyone in business and life.

76 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!