TodorMitev

DistanceBetween2Dates

Jan 25th, 2012
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Globalization;
  6.  
  7. namespace _16DistanceDays
  8. {
  9.     class DistanceDays
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             CultureInfo provider = CultureInfo.CurrentCulture;
  14.             string format = "d.MM.yyyy";
  15.  
  16.             Console.Write("Enter the first date: ");
  17.             string date1 = Console.ReadLine();
  18.             DateTime firstDate = DateTime.ParseExact(date1, format, provider);
  19.  
  20.             Console.Write("Enter the second date: ");
  21.             string date2 = Console.ReadLine();
  22.             DateTime secondDate = DateTime.ParseExact(date2, format, provider);
  23.  
  24.             TimeSpan result = secondDate-firstDate;
  25.             Console.WriteLine("Distance: {0} days",result.Days);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment