proseidon proseidon - 7 days ago 5x
C# Question

Setting a DateTime to the first of the next month?

If I have

var olddate = DateTime.Parse('05/13/2012');

and I want to get
var newdate = (the first of the month after olddate, 06/01/2012 in this case);

What would I code? I tried to set the month+1 but month has no setter.


Try this:

olddate = olddate.AddMonths(1);
DateTime newDate = new DateTime(olddate.Year, olddate.Month, 1, 
    0, 0, 0, olddate.Kind);