DateTime::CompareTo Method (DateTime)
Assembly: mscorlib (in mscorlib.dll)
- Type: System::DateTime
The object to compare to the current instance.
Return ValueType: System::Int32
A signed number indicating the relative values of this instance and the value parameter.
Less than zero
This instance is earlier than value.
This instance is the same as value.
Greater than zero
This instance is later than value.
This method implements the System::IComparable<T> interface and performs slightly better than the DateTime::CompareTo(Object) method overload because it does not have to convert the value parameter to an object.
The following example instantiates three DateTime objects, one that represents today's date, another that represents the date one year previously, and a third that represents the date one year in the future. It then calls the method and displays the result of the comparison.
.NET FrameworkSupported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
XNA FrameworkSupported in: 3.0, 2.0, 1.0
Portable Class LibrarySupported in: Portable Class Library
Supported in: Windows Phone 8.1
Supported in: Windows Phone Silverlight 8.1
Supported in: Windows Phone Silverlight 8