Advertisement
Guest User

DateModifier

a guest
Jun 26th, 2016
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2.  
  3. namespace DateModifier
  4. {
  5.     public class DateModifierMain
  6.     {
  7.         public static void Main()
  8.         {
  9.             string startDate = Console.ReadLine();
  10.             string endDate = Console.ReadLine();
  11.  
  12.             int differenceInDays = DateModifier.CalculateDifferenceInDays(startDate, endDate);
  13.  
  14.             Console.WriteLine(differenceInDays);
  15.         }
  16.     }
  17.  
  18.     public static class DateModifier
  19.     {
  20.         public static int CalculateDifferenceInDays(string dateOne, string dateTwo)
  21.         {
  22.             DateTime first = CreateDate(dateOne);
  23.             DateTime second = CreateDate(dateTwo);
  24.  
  25.             if (first <= second)
  26.             {
  27.                 int difference = (int) (second - first).TotalDays;
  28.                 return difference;
  29.             }
  30.  
  31.             else
  32.             {
  33.                 int difference = (int) (first - second).TotalDays;
  34.                 return difference;
  35.             }
  36.         }
  37.  
  38.         private static DateTime CreateDate(string dateOne)
  39.         {
  40.             var data = dateOne.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
  41.  
  42.             int year = int.Parse(data[0]);
  43.             int month = int.Parse(data[1]);
  44.             int day = int.Parse(data[2]);
  45.  
  46.             var date = new DateTime(year, month, day);
  47.             return date;
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement