TzvetanIG

Difference Between Dates

Mar 29th, 2014
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3.  
  4. class DifferenceBetweenDates
  5. {
  6.     static void Main()
  7.     {
  8.         try
  9.         {
  10.             CultureInfo bgBG = new CultureInfo("bg-BG");
  11.             string dateString = Console.ReadLine();
  12.             DateTime startDate = DateTime.ParseExact(dateString, "d.MM.yyyy", bgBG);
  13.             dateString = Console.ReadLine();
  14.             DateTime endDate = DateTime.ParseExact(dateString, "d.MM.yyyy", bgBG);
  15.  
  16.             TimeSpan difference = endDate - startDate;
  17.             Console.WriteLine(difference.Days);
  18.         }
  19.         catch (FormatException)
  20.         {
  21.             Console.WriteLine("Invalid date! Dates must be in format dd.MM.yyyy.");
  22.         }
  23.  
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment