DateTime dt = new DateTime();
dt = DateTime.Now.AddMonths(1);
int x = DateTime.DaysInMonth(dt.Year, dt.Month);
MessageBox.Show(x.ToString()); // works ok - 31
>
You can do:
DateTime dt = new DateTime();
dt = DateTime.Now.AddMonths(1);
DateTime conditionDateTime = new DateTime(dt.Year, dt.Month,DateTime.DaysInMonth(dt.Year, dt.Month));
for (DateTime dt1 = new DateTime(dt.Year, dt.Month, 1); dt1
This will give you
8/1/2012 : Wednesday
8/2/2012 : Thursday
8/3/2012 : Friday
8/4/2012 : Saturday
8/5/2012 : Sunday
8/6/2012 : Monday
8/7/2012 : Tuesday
8/8/2012 : Wednesday
8/9/2012 : Thursday
8/10/2012 : Friday
8/11/2012 : Saturday
8/12/2012 : Sunday
8/13/2012 : Monday
8/14/2012 : Tuesday
8/15/2012 : Wednesday
8/16/2012 : Thursday
8/17/2012 : Friday
......