proseidon proseidon - 1 year ago 78
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.

Answer Source

Try this:

olddate = olddate.AddMonths(1);
DateTime newDate = new DateTime(olddate.Year, olddate.Month, 1, 
    0, 0, 0, olddate.Kind);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download