Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DateTime.Equals Method

Returns a value indicating whether an instance of DateTime is equal to a specified object.

Overload List

Returns a value indicating whether this instance is equal to a specified object.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Overrides Public Function Equals(Object) As Boolean
[C#] public override bool Equals(object);
[C++] public: bool Equals(Object*);
[JScript] public override function Equals(Object) : Boolean;

Returns a value indicating whether two instances of DateTime are equal.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function Equals(DateTime, DateTime) As Boolean
[C#] public static bool Equals(DateTime, DateTime);
[C++] public: static bool Equals(DateTime, DateTime);
[JScript] public static function Equals(DateTime, DateTime) : Boolean;

Example

[Visual Basic, C#, C++] The following sample demonstrates the Equals method.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Equals. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Dim today1 As New System.DateTime(System.DateTime.Today.Ticks)
Dim today2 As New System.DateTime(System.DateTime.Today.Ticks)
Dim tomorrow As New System.DateTime( _
                        System.DateTime.Today.AddDays(1).Ticks)

' todayEqualsToday gets true.
Dim todayEqualsToday As Boolean = System.DateTime.Equals(today1, today2)

' todayEqualsTomorrow gets false.
Dim todayEqualsTomorrow As Boolean = System.DateTime.Equals(today1, tomorrow)

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

[C++] 
System::DateTime today1 = System::DateTime(System::DateTime::Today.Ticks);
System::DateTime today2 = System::DateTime(System::DateTime::Today.Ticks);
System::DateTime tomorrow = 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);

[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.

See Also

DateTime Structure | DateTime Members | System Namespace

Show:
© 2016 Microsoft