So how do we calculate the last date of the month which is 4 months from now?
SQL Server 2012 presents EOMONTH() function. Let us understand this function with an example.
DECLARE @MyDate datetime SET @MyDate = GETDATE() SELECT EOMONTH (@MyDate,4) SELECT EOMONTH (@MyDate,-4) as LastDayOfTheMonth
So what do we find from the 2 outputs. Well it gives me the last date of the 4th month from the current month i.e. 4 months from now would be April and the last date of April is 30th. The second output gives the last date of 4 months previous i.e August. This function would be very handy in calculations where the last date of the month is a critical factor. Previously to achieve this we would have to do a bit of manipulation.