// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; class MainClass { public static int[] doMonthDiff(DateTime start,DateTime end) { int months; int days; if(end.Day > start.Day) { months = end.Month - start.Month; days = end.Day - start.Day; } else { months = end.Month - start.Month - 1; days = end.Day - start.Day + DateTime.DaysInMonth(start.Year, start.Month); } return(new int[]{months,days}); } public static void Main(string[] args) { int[] tst1 = doMonthDiff(new DateTime(2004, 8, 14), new DateTime(2004, 9, 15)); Console.WriteLine(tst1[0] + " " + tst1[1]); int[] tst2 = doMonthDiff(new DateTime(2004, 8, 14), new DateTime(2004, 9, 13)); Console.WriteLine(tst2[0] + " " + tst2[1]); int[] tst3 = doMonthDiff(new DateTime(2004, 2, 20), new DateTime(2004, 3, 20)); Console.WriteLine(tst3[0] + " " + tst3[1]); int[] tst4 = doMonthDiff(new DateTime(2005, 2, 20), new DateTime(2005, 3, 20)); Console.WriteLine(tst4[0] + " " + tst4[1]); } }