You can find the last day of a month using EOMONTH function. In addition, you can use a second parameter that add a specific number of month to the specified value by the first parameter. The second parameter is optional.
EOMONTH with only first parameter:
1 2 3 |
SET DATEFORMAT ymd DECLARE @mydate DATETIME = '2019-02-21'; SELECT EOMONTH ( @mydate ) AS last_day_of_mydate; |
EOMONTH with two parameter:
1 2 3 |
SET DATEFORMAT ymd DECLARE @mydate DATETIME = '2019-02-21'; SELECT EOMONTH ( @mydate,2 ) AS last_day_of_mydate; |