Thursday, November 13, 2008

C# find last months date range

DateTime firstDay = new DateTime(DateTime.Now.AddMonths(-1).Year, DateTime.Now.AddMonths(-1).Month, 1);

int DaysinMonth = DateTime.DaysInMonth(DateTime.Now.AddMonths(-1).Year, DateTime.Now.AddMonths(-1).Month);

DateTime lastDay = firstDay.AddMonths(1).AddTicks(-1);

used code found here:
http://anuraj.wordpress.com/2007/12/03/last-day-and-first-day-of-the-month-using-c/