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# | Clone() Method
- C# | Math.Abs() Method | Set - 1
- C# | Math.Abs() Method | Set - 2
- C# | Math.Exp() Method
- C# | IndexOfAny() Method
- C# | Math.Sin() Method
- Decimal.Add() Method in C#
- C# | Dictionary.Add() Method
- C# | Math.Cos() Method
- C# | Math.Tan() Method
- C# | String.Contains() Method
- C# | Math.Min() Method
- C# | Insert() Method
- C# | Random.Next() 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 email@example.com. 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.