DateTime::CompareTo Method (Object)

Compares the value of this instance to a specified object that contains a specified DateTime value, and returns an integer that indicates whether this instance is earlier than, the same as, or later than the specified DateTime value.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

No code example is currently available or this language may not be supported.

Parameters

value
Type: System::Object
The object to compare to this instance, or nullptr.

Return Value

Type: System::Int32
A 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, or value is nullptr.

Implements

IComparable::CompareTo(Object)

ExceptionCondition
ArgumentException

value is not a DateTime.

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.

Any instance of DateTime, regardless of its value, is considered greater than nullptr.

The following example demonstrates the CompareTo method.

No code example is currently available or this language may not be supported.

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show: