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.
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.