Finding Month Ends in T-SQL
Months are funny. Unlike other parts of a date, they vary in length: The last second of a minute is always 59. The last minute of a hour is always 59. The last hour of a day is always 23. But the last day of a month? Well that depends on what month it is. And the year matters too because a leap year means February gets an extra day. This used to be somewhat tricky to calculate, but then for SQL Server 2012 Microsoft added the EOMONTH() function (End Of MONTH) to T-SQL to help with this. EOMONTH() takes…