Use the Equals() method to compare DateTime instances : DateTime : Date Time C# Examples


C# Examples » Date Time » DateTime »

 

Use the Equals() method to compare DateTime instances









    
using  System;

class  MainClass
{
    public  static  void  Main()
    {
        DateTime  myDateTime3  =  new  DateTime(2004,  1,  13);
        DateTime  myDateTime4  =  new  DateTime(2004,  1,  14);
        Console.WriteLine("myDateTime3  =  "  +  myDateTime3);
        Console.WriteLine("myDateTime4  =  "  +  myDateTime4);
        
        
        bool  boolResult  =  DateTime.Equals(myDateTime3,  myDateTime4);
        Console.WriteLine("DateTime.Equals(myDateTime3,  myDateTime4)  =  "  +  boolResult);
        boolResult  =  myDateTime3.Equals(myDateTime4);
        Console.WriteLine("myDateTime3.Equals(myDateTime4)  is  "  +  boolResult);
    }

}
    
   
  
   



Output

myDateTime3 = 13/01/2004 12:00:00 AM
myDateTime4 = 14/01/2004 12:00:00 AM
DateTime.Equals(myDateTime3, myDateTime4) = False
myDateTime3.Equals(myDateTime4) is False


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Date Time
» DateTime