Advertisement
Razhagal

Dates Difference

Mar 31st, 2014
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. class DatesDifference
  9. {
  10.     static TimeSpan DaysDifference(DateTime startDate, DateTime endDate)
  11.     {
  12.         TimeSpan days = endDate - startDate;
  13.  
  14.         return days;
  15.     }
  16.  
  17.     static void Main()
  18.     {
  19.         CultureInfo bgBG = new CultureInfo("bg-BG");
  20.  
  21.         try
  22.         {
  23.             DateTime startDate = DateTime.ParseExact(Console.ReadLine(), "d.MM.yyyy", bgBG);
  24.             DateTime endDate = DateTime.ParseExact(Console.ReadLine(), "d.MM.yyyy", bgBG);
  25.  
  26.             Console.WriteLine(DaysDifference(startDate, endDate).Days);
  27.         }
  28.         catch (FormatException)
  29.         {
  30.             Console.WriteLine("Invalid date! Dates must be in format dd.MM.yyyy.");
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement