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# | Remove() Method
- C# | Math.Abs() Method | Set - 1
- C# | PadLeft() Method
- C# | SortedDictionary.Add() Method
- C# | Clone() Method
- Main Method in C#
- C# | Math.Exp() Method
- C# | Method Parameters
- C# | PadRight() Method
- C# | Join() Method | Set - 1
- C# | Method Overriding
- C# | Dictionary.Add() Method
- C# | Join Method | Set - 2
- C# | IndexOfAny() 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.