DateTime::CompareTo Method (DateTime)
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Parameters
- value
- Type: System::DateTime
The object to compare to this instance.
Return Value
Type: System::Int32A signed integer that indicates the relationship between this instance and the value parameter, as shown in the following table.
Value | Description |
|---|---|
Less than zero | This instance is earlier than value. |
Zero | This instance is the same as value. |
Greater than zero | This instance is later than value. |
Implements
IComparable<T>::CompareTo(T)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.
Before comparing DateTime objects, make sure that the objects represent times in the same time zone. You can do this by comparing the values of their Kind properties.
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 CompareTo(DateTime) method and displays the result of the comparison.
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.