int Monthly = 1; DateTime StartDate = new DateTime(2012, 01, 01); DateTime EndDate = new DateTime(2012, 10, 01); for (DateTime i = StartDate; i < EndDate; i = i.AddMonths(Monthly)) { const int Thursday = 4; const int DayDiff = 7 - Thursday; //This will give me last day of month int Day = DateTime.DaysInMonth(i.Year, i.Month); //This will return any value from "0-7" where 0 is sunday. int DayOfWeek = (int)new DateTime(i.Year, i.Month, Day).DayOfWeek; DateTime _dtNew = new DateTime(i.Year, i.Month, Day).AddDays(-((DayOfWeek < Thursday) ? (DayOfWeek + DayDiff) : (DayOfWeek - Thursday))); Response.Write(_dtNew.ToString("dd-MMM-yyyy") + "
"); }
Reference: Muthukumar (http://nadarmuthukumar.blogspot.in)
Hope you liked this and let me know your thoughts on post through your comments :)
Hope you liked this and let me know your thoughts on post through your comments :)