fork(2) download
  1. using System;
  2. using System.Text;
  3. using System.Linq;
  4.  
  5. public class Quarter
  6. {
  7. public static long GetQuarters(DateTime dt1, DateTime dt2)
  8. {
  9. double d1Quarter = GetQuarter(dt1.Month);
  10. double d2Quarter = GetQuarter(dt2.Month);
  11. double d1 = d2Quarter - d1Quarter;
  12. double d2 = (4 * (dt2.Year - dt1.Year));
  13. return Round(d1 + d2);
  14. }
  15.  
  16. private static int GetQuarter(int nMonth)
  17. {
  18. if (nMonth <= 3)
  19. return 1;
  20. if (nMonth <= 6)
  21. return 2;
  22. if (nMonth <= 9)
  23. return 3;
  24. return 4;
  25. }
  26.  
  27. private static long Round(double dVal)
  28. {
  29. if (dVal >= 0)
  30. return (long)Math.Floor(dVal);
  31. return (long)Math.Ceiling(dVal);
  32. }
  33. }
  34.  
  35. public class Program
  36. {
  37.  
  38. public static void Main(string[] args)
  39. {
  40. DateTime dt1 = new DateTime(2012, 1, 1);
  41. DateTime dt2 = new DateTime(2013, 1, 15);
  42. long countQuarters = Quarter.GetQuarters(dt1, dt2);
  43. Console.Write("Quarters between: " + countQuarters);
  44. }
  45. }
Success #stdin #stdout 0.04s 33816KB
stdin
Standard input is empty
stdout
Quarters between: 4