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# | String.Contains() Method
- C# | Uri.IsHexDigit() Method
- C# | Uri.IsBaseOf(Uri) Method
- C# | Method Overriding
- C# | Math.Log() Method
- C# | Uri.FromHex() Method
- C# | Dictionary.Add() Method
- C# | Trim() Method
- C# | Math.Tan() Method
- C# | Math.Cos() Method
- C# | IndexOfAny() Method
- C# | CopyTo() Method
- C# | Math.Sin() Method
- C# | Math.Abs() Method | Set - 2
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.