svetlozar_kirkov

Distance between dates (Exercise)

Oct 11th, 2014
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Security.Policy;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace ConsoleTests
  7. {
  8.     class ConsoleTests
  9.     {
  10.         static void Main()
  11.         {
  12.             string dateStart = Console.ReadLine();
  13.             string dateEnd = Console.ReadLine();
  14.             DateTime start = DateTime.ParseExact(dateStart, "d.M.yyyy", CultureInfo.InvariantCulture);
  15.             DateTime end = DateTime.ParseExact(dateEnd, "d.M.yyyy", CultureInfo.InvariantCulture);
  16.             int count = 0;
  17.             for (DateTime i = start; i <= end; i=i.AddDays(1))
  18.             {
  19.                 if (i==end)
  20.                 {
  21.                     Console.WriteLine("Distance: {0} days",count);
  22.                     return;
  23.                 }
  24.                 else
  25.                 {
  26.                     count++;
  27.                 }
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment