EndOfTheMonth
Returns datetime corresponding to last day of the month
Source
public static DateTime EndOfTheMonth(this DateTime date)
{
var endOfTheMonth = new DateTime(date.Year, date.Month, 1)
.AddMonths(1)
.AddDays(-1);
return endOfTheMonth;
}
Example
var lastDay = DateTime.Now.EndOfTheMonth();