Sunday, 9 April 2017

C# Program to Compare Two Dates

  1. /*
  2.  * C# Program to Campare Two Dates
  3.  */
  4. using System;
  5. namespace DateAndTime
  6. {
  7.     class Program
  8.     {
  9.         static int Main()
  10.         {
  11.             DateTime sd = new DateTime(2010, 10, 12);
  12.             Console.WriteLine("Starting Date : {0}", sd);
  13.             DateTime ed = sd.AddDays(10);
  14.             Console.WriteLine("Ending Date   : {0}", ed);
  15.             if (sd < ed)
  16.                 Console.WriteLine("{0} Occurs Before {1}", sd, ed);
  17.             Console.Read();
  18.             return 0;
  19.  
  20.         }
  21.     }
  22. }
Here is the output of the C# Program:
Starting Date : 10/11/2010  12:00:00 AM
Ending Date   : 10/21/2010  12:00:00 AM
10/11/2010 12:00:00 Am Occurs Before 10/21/2010 12:00:00 AM

No comments:

Post a Comment