DateTimeOffset.Compare Method (DateTimeOffset, DateTimeOffset)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Compares two DateTimeOffset objects and indicates whether the first is earlier than the second, equal to the second, or later than the second.

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

static member Compare : 
        first:DateTimeOffset *
        second:DateTimeOffset -> int


Type: System.DateTimeOffset

The first object to compare.

Type: System.DateTimeOffset

The second object to compare.

Return Value

Type: System.Int32

A signed integer that indicates whether the value of the first parameter is earlier than, later than, or the same time as the value of the second parameter, as the following table shows.

Return value


Less than zero

first is earlier than second.


first is equal to second.

Greater than zero

first is later than second.

In performing the comparison, the method converts both the first and the second parameters to Coordinated Universal Time (UTC) before it performs the comparison. The method is equivalent to the following:

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

In other words, the Compare method determines whether two DateTimeOffset objects represent a single point in time. It directly compares neither dates and times nor offsets.

The following example illustrates calls to the Compare method to compare DateTimeOffset objects.

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

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top