asp.net.ph

DateTime.Compare Method

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;

Parameters

t1
The first DateTime.
t2
The second DateTime.

Return Value

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.

Example

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" );
  C# VB

See Also

DateTime Members   CompareTo   Equals Skip Navigation Links




Previous page Back to top Next page

Check out related books at Amazon

© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note