System Namespace DateTime Structure
Compares two instances of DateTime and returns an indication of their relative values.
[ VB ]
<Serializable>
Public Shared Function Compare ( _
ByVal t1 As DateTime, _
ByVal t2 As DateTime _
} As Integer
[ C# ]
[ Serializable ]
public static int Compare (
DateTime t1,
DateTime t2
};
[ C++ ]
[ Serializable ]
public: static int Compare (
DateTime t1,
DateTime t2
};
[ JScript ]
public Serializable
static function Compare (
t1 : DateTime,
t2 : DateTime
} : int;
- t1
- The first DateTime.
- t2
- The second DateTime.
A signed number indicating the relative values of t1 and t2.
Value Type |
Condition |
Less than zero |
t1 is less than t2. |
Zero |
t1 equals t2. |
Greater than zero |
t1 is greater than t2. |
The below code snippet demonstrates using the Compare.
DateTime t1 = new DateTime ( 100 );
DateTime t2 = new DateTime ( 20 );
if ( DateTime.Compare ( t1, t2 ) > 0 ) Response.WriteLine ( "t1 > t2" );
if ( DateTime.Compare ( t1, t2 ) == 0 ) Response.WriteLine ( "t1 == t2" );
if ( DateTime.Compare ( t1, t2 ) < 0 ) Response.WriteLine ( "t1 < t2" );
Dim t1 As New DateTime ( 100 )
Dim t2 As New DateTime ( 20 )
If DateTime.Compare ( t1, t2 ) > 0 Then
Response.WriteLine ( "t1 > t2" )
End If
If DateTime.Compare ( t1, t2 ) = 0 Then
Response.WriteLine ( "t1 == t2" )
End If
If DateTime.Compare ( t1, t2 ) < 0 Then
Response.WriteLine ( "t1 < t2" )
End If |
|
C# |
VB |
DateTime Members CompareTo Equals