Advertisement
anizko

Untitled

Oct 17th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Globalization;
  4.  
  5. namespace DefiningClasses
  6. {
  7.     public class StartUp
  8.     {
  9.         public static void Main()
  10.         {
  11.             var firstDate = Console.ReadLine();
  12.             var secondDate = Console.ReadLine();
  13.             Console.WriteLine(DateModifier.GetDaysBetweenDates(firstDate, secondDate));
  14.         }
  15.     }
  16.     public static class DateModifier
  17.     {
  18.         public static double GetDaysBetweenDates(string dateOne, string dateTwo)
  19.         {
  20.             var firstDate = DateTime.ParseExact(dateOne, "yyyy MM dd", CultureInfo.InvariantCulture);
  21.             var secondDate = DateTime.ParseExact(dateTwo, "yyyy MM dd", CultureInfo.InvariantCulture);
  22.  
  23.             if (firstDate > secondDate)
  24.             {
  25.                 return GetDaysBetweenDates(dateTwo, dateOne);
  26.             }
  27.  
  28.             return (secondDate - firstDate).Days;
  29.         }
  30.     }
  31.  
  32.  
  33.    
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement