I have client side date validation that requires one particular Date to be one month from a different date so I use d.setMonth(d.getMonth() + 1) and mostly works just fine.
For end of month issues as in 1/31/2009, it returns 3/3/2009 and that’s great – that’s how I’d prefer it handle it.
In the code behind, I’m also generating this date but DateTime.AddMonths(1) returns 2/28/2009 so that’s no good.
Is there some way around this?
From your example of 1/31/2009 being changed to 3/3/2009 it sounds like you just want a way to advance the specified date by the number of days in its respective month. (Adding 31 days to the date if it’s in January, 28 if in February during a non-leap year, etc…)
So your code would look something like: