Export (0) Print
Expand All

DateTime Equality Operator

Determines whether two specified instances of DateTime are equal.

[Visual Basic]
returnValue = DateTime.op_Equality(d1, d2)
[C#]
public static bool operator ==(
 DateTime d1,
 DateTime d2
);
[C++]
public: static bool op_Equality(
 DateTime d1,
 DateTime d2
);
[JScript]
returnValue = d1 == d2;

[Visual Basic] In Visual Basic, you can use the operators defined by a type, but you cannot define your own. You can use the Equals method instead of the DateTime equality operator.

[JScript] In JScript, you can use the operators defined by a type, but you cannot define your own.

Arguments [Visual Basic, JScript]

d1
A DateTime.
d2
A DateTime.

Parameters [C#, C++]

d1
A DateTime.
d2
A DateTime.

Return Value

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

Example

[Visual Basic, C#, C++] The following sample demonstrates the equality operator.

[Visual Basic] 
Dim april19 As New DateTime(2001, 4, 19)
Dim otherDate As New DateTime(1991, 6, 5)

Dim areEqual As Boolean
' areEqual gets false.
areEqual = System.DateTime.op_Equality(april19, otherDate)

otherDate = New DateTime(2001, 4, 19)
' areEqual gets true.
areEqual = System.DateTime.op_Equality(april19, otherDate)

[C#] 
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;

[C++] 
System::DateTime april19(2001, 4, 19);
System::DateTime otherDate(1991, 6, 5);

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

DateTime Structure | DateTime Members | System Namespace | Boolean

Show:
© 2014 Microsoft