Advertisement
Stann

DifferenceBetweenDates

Mar 29th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. class DifferenceBetweenDates
  4. {
  5.     static void Main()
  6.     {
  7.         //Write a program that enters two dates in format dd.MM.yyyy and returns the number of days between them.
  8.  
  9.         string firstInput = Console.ReadLine();
  10.         DateTime firstDate = DateTime.ParseExact(firstInput, "d.MM.yyyy", CultureInfo.CurrentCulture);
  11.         string secondInput = Console.ReadLine();
  12.         DateTime secondDate = DateTime.ParseExact(secondInput, "d.MM.yyyy", CultureInfo.CurrentCulture);
  13.         int days = (int)NumberOfDays(firstDate, secondDate);
  14.         Console.WriteLine(days);
  15.     }
  16.     static double NumberOfDays(DateTime first,DateTime second)
  17.     {
  18.         TimeSpan difference = second - first;
  19.         int result = (int)difference.TotalDays;
  20.         return result;
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement