Equality Operator

DateTime.Equality Operator (DateTime, DateTime)


Determines whether two specified instances of DateTime are equal.

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

public static bool operator ==(
	DateTime d1,
	DateTime d2


Type: System.DateTime

The first object to compare.

Type: System.DateTime

The second object to compare.

Return Value

Type: System.Boolean

true if d1 and d2 represent the same date and time; otherwise, false.

The Equality operator determines whether two DateTime values are equal by comparing their number of ticks. 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 property.

The following example demonstrates the equality operator.

System.DateTime april19 = new DateTime(2001, 4, 19);
System.DateTime otherDate = new DateTime(1991, 6, 5);

// areEqual gets false.
bool areEqual = april19 == otherDate;

otherDate = new DateTime(2001, 4, 19);
// areEqual gets true.
areEqual = april19 == otherDate;

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
© 2015 Microsoft