Thursday, October 8, 2009

Start day, dayname and end day of the month

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

//Get startday of month
DateTime firstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

//Get endday of month
DateTime.DaysInMonth(DateTime.Now.Year,DateTime.Now.Month)

if day is 1 of any month use DateTime.Now.DayOfWeek returns dayname
else DateTime.Now.AddDays(-(DateTime.Now.Day-1)).DayOfWeek returns dayname

No comments: