Quote Originally Posted by cpradio View Post
I see your point, so my basis is flawed to. PHP is currently subtracting the number of days in the preceding month, thus the March 31st minus a month is March 2nd, which is still wrong... So obviously it is a bit more complex than that too.

This is why I agree with .NET:
Code c#:
var march = new DateTime(2012, 03, 31);
var may = new DateTime(2012, 05, 31);
Console.WriteLine(may.ToString("yyyy-MM-dd"));
var april = may.AddMonths(-1);
Console.WriteLine(april.ToString("yyyy-MM-dd"));
 
var march = new DateTime(2012, 03, 31);
Console.WriteLine(march.ToString("yyyy-MM-dd"));
var february = march.AddMonths(-1);
Console.WriteLine(february.ToString("yyyy-MM-dd"));
var january = february.AddMonths(-1);
Console.WriteLine(january.ToString("yyyy-MM-dd"));
Console.ReadKey();
/*
  Output:
  2012-05-31
  2012-04-30
  2012-03-31
  2012-02-29
  2012-01-29 // this one irks me a bit, but it is understandable.
*/

I have to give it to the MS folks, they really made it nice and maybe I just expect other languages to do it as well.
It's a little interesting because, based on results you've posted, .NET behavior will match common sense but break mathematics. For example:

2012-03-31 -1 month returns 2012-02-29, and 2012-02-29 +1 month returns 2012-03-29. In other words, x + 1 -1 != x.