fork(3) download
using System;
using System.Text;
using System.Linq;

        public class Quarter
        {
            public static long GetQuarters(DateTime dt1, DateTime dt2)
            {
                double d1Quarter = GetQuarter(dt1.Month);
                double d2Quarter = GetQuarter(dt2.Month);
                double d1 = d2Quarter - d1Quarter;
                double d2 = (4 * (dt2.Year - dt1.Year));
                return Round(d1 + d2);
            }

            private static int GetQuarter(int nMonth)
            {
                if (nMonth <= 3)
                    return 1;
                if (nMonth <= 6)
                    return 2;
                if (nMonth <= 9)
                    return 3;
                return 4;
            }

            private static long Round(double dVal)
            {
                if (dVal >= 0)
                    return (long)Math.Floor(dVal);
                return (long)Math.Ceiling(dVal);
            }
        }
 
public class Program
{
 
public static void Main(string[] args)
{
            DateTime dt1 = new DateTime(2012, 1, 1);
            DateTime dt2 = new DateTime(2013, 1, 15);
            long countQuarters = Quarter.GetQuarters(dt1, dt2);
            Console.Write("Quarters between: " + countQuarters);
}
}
Success #stdin #stdout 0.04s 33816KB
stdin
Standard input is empty
stdout
Quarters between: 4