var now = DateTime.Now;
var startOfMonth = new DateTime(now.Year, now.Month, 1);
var DaysInMonth = DateTime.DaysInMonth(now.Year, now.Month);
var lastDay = new DateTime(now.Year, now.Month, DaysInMonth);
public static int DaysInMonthBy(this DateTime src, Calendar calendar)
{
var year = calendar.GetYear(src); // year of src in your calendar
var month = calendar.GetMonth(src); // month of src in your calendar
var lastDay = calendar.GetDaysInMonth(year, month); // days in month means last day of that month in your calendar
return lastDay;
}
// Use any date you want, for the purpose of this example we use 1980-08-03.
var myDate = new DateTime(1980,8,3);
var lastDayOfMonth = new DateTime(myDate.Year, myDate.Month, DateTime.DaysInMonth(myDate.Year, myDate.Month));