C# DateTime Equals() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DateTime

Definition

In C#, DateTime.Equals returns true when two values have the same number of ticks. It does not look at the Kind flag.

There are three forms: a.Equals(b) for a DateTime, a.Equals(obj) for any object, and the static DateTime.Equals(a, b). The == operator gives the same answer as the first form.

Equals comes in instance form (dt.Equals(...)) and static form (DateTime.Equals(...)). DateTime is an immutable struct, so each call gives you a result and leaves the original alone.

Syntax

Use the instance method or the static method.

C#
DateTime a = new DateTime(2026, 11, 18, 10, 0, 0);
DateTime b = new DateTime(2026, 11, 18, 10, 0, 0);
bool r1 = a.Equals(b);               // true
bool r2 = DateTime.Equals(a, b);     // true
bool r3 = a.Equals((object)"text");  // false
CallWhat it does
a.Equals(b)True when both have the same ticks.
DateTime.Equals(a, b)Static form with two DateTime arguments.
a.Equals(obj)False when obj is null or not a DateTime.

Equality needs the whole value to match, including seconds and fractions. To ignore the time, compare the Date property of each value.

Library declarations
C#
public bool Equals(DateTime value);
public override bool Equals(object? value);
public static bool Equals(DateTime t1, DateTime t2);

Parameters

ParameterDescription
valueThe date or object to compare with this instance (instance overloads).
t1, t2Two DateTime values to compare (static overload).

Return Value

Return ValueDescription
booltrue if both values have the same ticks; otherwise false.

C# Examples

Example 1 — Equal and Not Equal

Compare two identical values, then a value one second later.

C#
using System;

class Program {
    static void Main() {
        DateTime a = new DateTime(2026, 11, 18, 10, 0, 0);
        DateTime b = new DateTime(2026, 11, 18, 10, 0, 0);
        DateTime c = a.AddSeconds(1);
        Console.WriteLine(a.Equals(b));
        Console.WriteLine(a.Equals(c));
        Console.WriteLine(a == b);
    }
}

How It Works

  1. Two copies. a and b are built from the same numbers, so the ticks match.
  2. One second apart. c is a second later, so it is a different value.
  3. Exact match only. Even a one-second gap makes Equals return False.
  4. Operator. a == b uses the same rule, so it prints True.

Example 2 — Static and Object Overloads

Use DateTime.Equals, then ask a date if it equals a string and null.

C#
using System;

class Program {
    static void Main() {
        DateTime a = new DateTime(2026, 11, 18);
        DateTime b = new DateTime(2026, 11, 18);
        Console.WriteLine(DateTime.Equals(a, b));
        Console.WriteLine(a.Equals((object)"2026-11-18"));
        Console.WriteLine(a.Equals(null));
    }
}

How It Works

  1. Static call. DateTime.Equals(a, b) has no instance on the left, so it needs both values.
  2. String is not a date. Text with the same look is still a different type, so the answer is False.
  3. Null. A DateTime is never equal to null, so the last line is False.
  4. No exception. The object overload quietly returns false for wrong types.

Example 3 — Kind Ignored, Date Property

Compare Utc with Local, then compare a time to midnight.

C#
using System;

class Program {
    static void Main() {
        DateTime utc = new DateTime(2026, 11, 18, 10, 0, 0, DateTimeKind.Utc);
        DateTime local = new DateTime(2026, 11, 18, 10, 0, 0, DateTimeKind.Local);
        DateTime noon = new DateTime(2026, 11, 18, 12, 0, 0);
        Console.WriteLine(utc.Equals(local));
        Console.WriteLine(noon.Equals(new DateTime(2026, 11, 18)));
        Console.WriteLine(noon.Date.Equals(new DateTime(2026, 11, 18)));
    }
}

How It Works

  1. Different Kind. One value is Utc and the other Local, but both have the same ticks.
  2. Equal anyway. Equals ignores Kind, so the first line is True.
  3. Noon vs midnight. The time of day differs, so the second line is False.
  4. Date property. noon.Date is midnight of that day, so the last comparison is True.

Frequently Asked Questions

For two DateTime values, yes. Both compare ticks.
No. A Utc and a Local value with the same ticks are equal.
Compare the Date property: a.Date == b.Date.
It returns false. No DateTime equals null.
The time part or the fractions of a second may differ. Equality needs every tick to match.

Next: FromBinary()

Rebuild a DateTime from the 64-bit number made by ToBinary with System.DateTime.

FromBinary() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful