C# DateTime Equality

Description

DateTime Equality determines whether two specified instances of DateTime are equal.

Syntax

DateTime.Equality has the following syntax.


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

Parameters

DateTime.Equality has the following parameters.

  • d1 - The first object to compare.
  • d2 - The second object to compare.

Returns

DateTime.Equality method returns true if d1 and d2 represent the same date and time; otherwise, false.

Example

The following example demonstrates the equality operator.


using System;//from  www.j  av  a  2s  .  c  o  m
public class MainClass{
  public static void Main(String[] argv){  
            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;

            System.Console.WriteLine(areEqual);
  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version