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
Call
What 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 - b
Operator 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
Parameter
Description
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 Value
Description
TimeSpan
From Subtract(DateTime). Positive when this date is later, negative when it is earlier.
DateTime
From 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);
}
}
Output
37.00:00:00
37
How It Works
Two fixed dates. December 25 and November 18, 2026, both at midnight.
Result is a TimeSpan. The first line prints days, then hours:minutes:seconds, so 37.00:00:00.
Count the days. November has 30 days: 12 days left plus 25 gives 37.
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));
}
}