Compares two DateTime values.
[Visual Basic] Public Shared Function Compare( _ ByVal t1 As DateTime, _ ByVal t2 As DateTime _ ) As Integer [C#] public static int Compare( DateTime t1, DateTime t2 ); [C++] public: static int Compare( DateTime t1, DateTime t2 ); [JScript] public static function Compare( t1 : DateTime, t2 : DateTime ) : int;
Value Type | Condition |
---|---|
1 | If the first value is less than the second value. |
0 | If the values are equal. |
-1 | If the first value is greater than the second value. |
The Compare method is used the same method as Currency to compare two numbers. It returns an integer representing the results of that comparison:
The values (same as Currency, a negative number) are determined using the following equations:
1 if t 1 > t 2, 0 if t 1 = t 2, or-1 if t 1 < t 2.
DateTime t1 =...
DateTime t2 = ...
If (DateTime.Compare (t1, t2) > 0) Console.WriteLine ("t1 > t2"); If (DateTime.Compare (t1, t2) == 0) Console.WriteLine ("t1 == t2"); If (DateTime.Compare (t1, t2) < 0) Console.WriteLine ("t1 < t2");
DateTime Structure | DateTime Members | System Namespace | CompareTo | Int32