Compare two DateTime and returns an integer that indicates the sequence in CSharp
Description
The following code shows how to compare two DateTime and returns an integer that indicates the sequence.
Example
//w w w . ja v a 2s. c o m
using System;
public class Example
{
public static void Main()
{
DateTime date1 = new DateTime(2009, 8, 1, 0, 0, 0);
DateTime date2 = new DateTime(2009, 8, 1, 12, 0, 0);
int result = DateTime.Compare(date1, date2);
if (result < 0)
Console.WriteLine("is earlier than");
else if (result == 0)
Console.WriteLine("is the same time as");
else
Console.WriteLine("is later than");
}
}
The code above generates the following result.