System.DateTime.Compare Method

Compares 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.

Syntax

public static int Compare (DateTime t1, DateTime t2)

Parameters

t1
The first object to compare.
t2
The second object to compare.

Returns

A signed number indicating the relative values of t1 and t2.

Less than zero

t1 is earlier than t2.

Zero

t1 is the same as t2.

Greater than zero

t1 is later than t2.

Remarks

Before comparing DateTime objects, ensure that the objects represent times in the same time zone.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0