This method is used to compare two instances of DateTime and returns an integer that indicates whether the first instance is earlier than, the same as, or later than the second instance.
public static int Compare (DateTime t1, DateTime t2);
- t1: The first object to compare.
- t2: The second object to compare.
Return Value: This method returns a signed number indicating the relative values of t1 and t2.
Less than zero : If t1 is earlier than t2.
Zero : If t1 is the same as t2.
Greater than zero : If t1 is later than t2.
Below programs illustrate the use of DateTime.Compare(DateTime, DateTime) Method:
date1 is later than date2.
01/03/2010 is earlier than 01/04/2010. 01/05/2010 is later than 01/04/2010. 01/05/2010 is the same as 01/05/2010.
- Difference between Method Overriding and Method Hiding in C#
- C# | Math.Min() Method
- Method Hiding in C#
- C# | Math.Log() Method
- C# | SortedDictionary.Add() Method
- C# | StartsWith() Method
- C# | Dictionary.Add() Method
- C# | CompareOrdinal() Method
- TimeSpan.Add() Method in C#
- Queue.Contains() Method in C#
- Decimal.Add() Method in C#
- C# | Math.Max() Method
- C# | IsNullOrEmpty() Method
- C# | Uri.GetHashCode() Method
- C# | PadLeft() Method
- DateTime.Add() Method in C#
- C# | Join() Method | Set - 1
- C# | Math.Tan() Method
- C# | Math.Cos() Method
- C# | Math.Sin() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.