Suppose you want to find the last day of the previous month, you can always use this method:
The above code finds the month difference between 1900-01-01 and current date and adds it to same date, so the result is first day of the month. Adding -1 to this result returns the last day of previous month. This is a very common approach where we use the DATEADD and DATEDIFF functions.
There is another method of finding the Last day of previous month where we will not use the dateadd and datediff functions. Here it goes:
select cast(getdate()-day(getdate()) as date)
The code shown above subtracts DAY from GETDATE(), so it returns last day of previous month.
Casting it to the DATE data type gives only the date.