CompareTo Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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)

'Declaration
Public Function CompareTo ( _
	val As Object _
) As Integer

Parameters

val
Type: System..::..Object
A boxed object to compare, or nullNothingnullptrunita null reference (Nothing in Visual Basic).

Return Value

Type: System..::..Int32
A signed number indicating the relative values of this instance and value.

Value

Description

Less than zero

This instance is earlier than val.

Zero

This instance is the same as val.

Greater than zero

This instance is later than val, or val is nullNothingnullptrunita null reference (Nothing in Visual Basic).

ExceptionCondition
ArgumentException

val 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 nullNothingnullptrunita null reference (Nothing in Visual Basic).

Show: