In my previous blog post i have demonstrated how to find first and last date of any month. SQL Server 2012 has introduced a new date function EOMONTH to find the last day of the month.
Syntax
EOMONTH ( start_date [, month_to_add ] )
Arguments
start_date
Date expression specifying the date for which to return the last day of the month.
month_to_add
Optional integer expression specifying the number of months to add to start_date.
Examples
EOMONTH without the month_to_add parameter to find last day of current month
EOMONTH with the month_to_add parameter to find last day of last and next month
SQL Server doesn’t provide any function to find start of the month, but we can make use of EOMONTH function to find start date of any month.
EOMONTH function is available in SQL Server 2012 and higher, for SQL Server 2008 R2 and below you can refer to this blog post.