DateTime.Equals Method (DateTime, DateTime)

July 28, 2014

Returns a value indicating whether two DateTime instances have the same date and time value.

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

public static bool Equals(
	DateTime t1,
	DateTime t2
)

Parameters

t1
Type: System.DateTime
The first object to compare.
t2
Type: System.DateTime
The second object to compare.

Return Value

Type: System.Boolean
true if the two DateTime values are equal; otherwise, false.

t1 and t2 are equal if their Ticks property values are equal. Their Kind property values are not considered in the test for equality.

The following example demonstrates the Equals method.


System.DateTime today1 =
      new System.DateTime(System.DateTime.Today.Ticks);
System.DateTime today2 =
      new System.DateTime(System.DateTime.Today.Ticks);
System.DateTime tomorrow =
      new System.DateTime(
               System.DateTime.Today.AddDays(1).Ticks);

// todayEqualsToday gets true.
bool todayEqualsToday = System.DateTime.Equals(today1, today2);

// todayEqualsTomorrow gets false.
bool todayEqualsTomorrow = System.DateTime.Equals(today1, tomorrow);


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft