System.DateTime.CompareTo Method

Compares the value of this instance to 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.

Syntax

public int CompareTo (DateTime value)

Parameters

value
The object to compare to the current instance.

Returns

A signed number indicating the relative values of this instance and the value parameter.

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.

Remarks

This method implements the IComparable`1 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 DateTime.Kind properties.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0