Saturday, January 8, 2011

Calculate month between two date

DateTime d1 = new DateTime(2002, 1, 1); 

DateTime d2 = new DateTime(2000, 10, 1); 

int M = Math.Abs((d1.Year - d2.Year)); 

int months = ((M * 12) + Math.Abs((d1.Month - d2.Month)));

No comments:

Post a Comment