C# DateTime Subtract() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DateTime

Definition

In C#, DateTime.Subtract has two overloads. Subtract(DateTime) returns the gap between two dates as a TimeSpan. Subtract(TimeSpan) returns a new DateTime that is earlier.

The - operator does the same job, so a - b and a.Subtract(b) are equal. If the other date is later, the TimeSpan is negative.

This is an instance member of System.DateTime. You call it on a DateTime value, such as dt.Subtract(...). DateTime is a struct, so every value is copied and never changed in place.

Syntax

Pass either a DateTime or a TimeSpan.

C#
DateTime a = new DateTime(2026, 12, 25);
DateTime b = new DateTime(2026, 11, 18);
TimeSpan gap = a.Subtract(b);                       // DateTime -> TimeSpan
DateTime earlier = b.Subtract(TimeSpan.FromDays(3)); // TimeSpan -> DateTime
CallWhat it does
a.Subtract(b)Time between two dates, as a TimeSpan (negative if b is later).
b.Subtract(TimeSpan.FromDays(3))The date three days before b.
a - bOperator form of the first overload.

Read the answer with gap.TotalDays, gap.TotalHours, or gap.TotalMinutes for decimal totals. The Days, Hours, and Minutes properties give only the part of each unit.

Library declarations
C#
public TimeSpan Subtract(DateTime value);
public DateTime Subtract(TimeSpan value);

Parameters

ParameterDescription
value (DateTime)Required in the first overload. The date to subtract from this one.
value (TimeSpan)Required in the second overload. The amount of time to go back.

Return Value

Return ValueDescription
TimeSpanFrom Subtract(DateTime). Positive when this date is later, negative when it is earlier.
DateTimeFrom Subtract(TimeSpan). A new date earlier than this one.

C# Examples

Example 1 — Count Days Between Two Dates

Subtract one date from another and read TotalDays.

C#
using System;

class Program {
    static void Main() {
        DateTime due = new DateTime(2026, 12, 25);
        DateTime today = new DateTime(2026, 11, 18);
        TimeSpan gap = due.Subtract(today);
        Console.WriteLine(gap);
        Console.WriteLine(gap.TotalDays);
    }
}

How It Works

  1. Two fixed dates. December 25 and November 18, 2026, both at midnight.
  2. Result is a TimeSpan. The first line prints days, then hours:minutes:seconds, so 37.00:00:00.
  3. Count the days. November has 30 days: 12 days left plus 25 gives 37.
  4. TotalDays. It is a double, so a whole number prints as 37.

Example 2 — Go Back by a TimeSpan

Use the TimeSpan overload to get an earlier DateTime.

C#
using System;
using System.Globalization;

class Program {
    static void Main() {
        DateTime dt = new DateTime(2026, 11, 18, 14, 30, 45);
        TimeSpan back = new TimeSpan(1, 2, 30, 0);
        DateTime earlier = dt.Subtract(back);
        Console.WriteLine(earlier.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
    }
}

How It Works

  1. Four-part span. new TimeSpan(1, 2, 30, 0) is 1 day, 2 hours, 30 minutes, 0 seconds.
  2. Go back one day. That moves the date to November 17 at 14:30:45.
  3. Then 2h 30m. 14:30:45 minus 2:30:00 is 12:00:45.
  4. DateTime result. This overload returns a date, not a span.

Example 3 — Hours Worked and Negative Spans

Subtract start from end, then reverse the order to get a negative span.

C#
using System;

class Program {
    static void Main() {
        DateTime start = new DateTime(2026, 11, 18, 9, 15, 0);
        DateTime end = new DateTime(2026, 11, 18, 17, 45, 0);
        Console.WriteLine(end.Subtract(start));
        Console.WriteLine(start.Subtract(end));
        Console.WriteLine(end.Subtract(start).TotalMinutes);
    }
}

How It Works

  1. Shift length. 17:45 minus 09:15 is 8 hours and 30 minutes, printed as 08:30:00.
  2. Reverse order. Subtracting the later value from the earlier one gives a negative span.
  3. Minus sign. The second line shows -08:30:00.
  4. TotalMinutes. 8 hours 30 minutes is 510 minutes in total.

Frequently Asked Questions

Subtract(DateTime) returns a TimeSpan. Subtract(TimeSpan) returns a DateTime.
Yes. The operator calls the same logic.
Use (later - earlier).TotalDays, or the Days property for whole days only.
The TimeSpan is negative, for example -08:30:00.
No. It compares ticks. Convert both values to UTC first when kinds differ.

Next: ToBinary()

Turn a DateTime into one 64-bit number that holds both ticks and Kind with System.DateTime.

ToBinary() 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.

13 people found this page helpful