Re: DateTime.AddMonths bug?
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Wed, 21 Dec 2005 19:06:44 -0000
Joe <jbassking@xxxxxxxxxxxxxxx> wrote:
> Why doesn't AddMonths add the correct number of days for a given month that
> is being added?
>
> For example:
>
> new DateTime(2005, 11, 30).AddMonths(1) returns 12/30/2005.
>
> Shouldn't this return 12/31/2005?
Why would it? It's thirty days into November, plus a month. For me,
that should return thirty days into December.
It gets more tricky when you add a month from the 30th of January, and
unfortunately the behaviour isn't actually specified in the docs as far
as I can see. I'd expect it to give February 28th (or 29th for a leap
year), that being the closest to February 30th which is actually
possible. I don't see that there's any ambiguity in your situation
though.
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- Follow-Ups:
- Re: DateTime.AddMonths bug?
- From: Ignacio Machin \( .NET/ C# MVP \)
- Re: DateTime.AddMonths bug?
- References:
- DateTime.AddMonths bug?
- From: Joe
- DateTime.AddMonths bug?
- Prev by Date: Re: DateTime.AddMonths bug?
- Next by Date: Re: TextBox backgrounds yellow (some of them)
- Previous by thread: Re: DateTime.AddMonths bug?
- Next by thread: Re: DateTime.AddMonths bug?
- Index(es):
Relevant Pages
|