SHARE
TWEET

DifferenceBetweenDates

Stann Mar 29th, 2014 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top