C# DateTime Add() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DateTime

Definition

In C#, DateTime.Add takes a TimeSpan and returns a new DateTime that is that far from the original. A positive span moves forward; a negative span moves back.

Use Add when you already have a TimeSpan, for example the result of another subtraction. If you only have a number of days or hours, AddDays and AddHours are shorter.

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

Syntax

Call Add on a DateTime value and pass a TimeSpan.

C#
DateTime dt = new DateTime(2026, 11, 18, 14, 30, 45);
DateTime a = dt.Add(new TimeSpan(2, 15, 30));   // +2h 15m 30s
DateTime b = dt.Add(TimeSpan.FromDays(1));      // +1 day
DateTime c = dt.Add(TimeSpan.FromHours(-20));   // back 20 hours
CallWhat it does
dt.Add(new TimeSpan(2, 15, 30))Move forward by 2 hours, 15 minutes, 30 seconds.
dt.Add(TimeSpan.FromDays(1))Move forward by one day (24 hours).
dt.Add(TimeSpan.FromHours(-20))A negative TimeSpan moves the date back.

Add returns a result and never edits dt. If the answer would fall before DateTime.MinValue or after DateTime.MaxValue, it throws ArgumentOutOfRangeException.

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

Parameters

ParameterDescription
valueRequired. A TimeSpan. It can be positive or negative and may include fractions of a second.

Return Value

Return ValueDescription
DateTimeA new DateTime equal to this value plus value. It keeps the same Kind.

C# Examples

Example 1 — Add a TimeSpan

Move a fixed time forward and show that the original value is unchanged.

C#
using System;
using System.Globalization;

class Program {
    static string Show(DateTime d) => d.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);

    static void Main() {
        DateTime dt = new DateTime(2026, 11, 18, 14, 30, 45);
        TimeSpan gap = new TimeSpan(2, 15, 30);
        DateTime later = dt.Add(gap);
        Console.WriteLine(Show(dt));
        Console.WriteLine(Show(later));
    }
}

How It Works

  1. Build a span. new TimeSpan(2, 15, 30) means 2 hours, 15 minutes, 30 seconds.
  2. Add it. 14:30:45 plus 2:15:30 gives 16:46:15 on the same day.
  3. Original kept. The first line still shows 14:30:45 because Add returns a new value.
  4. Helper method. Show prints a fixed pattern so the output never depends on your culture.

Example 2 — Negative TimeSpan

Pass a negative span to move to the previous day.

C#
using System;
using System.Globalization;

class Program {
    static string Show(DateTime d) => d.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);

    static void Main() {
        DateTime dt = new DateTime(2026, 11, 18, 14, 30, 45);
        DateTime earlier = dt.Add(TimeSpan.FromHours(-20));
        Console.WriteLine(Show(earlier));
        Console.WriteLine(earlier.Date == dt.Date);
    }
}

How It Works

  1. Minus 20 hours. TimeSpan.FromHours(-20) is a span that points backward.
  2. Cross midnight. 14:30:45 minus 20 hours lands at 18:30:45 on November 17.
  3. Date part changed. The Date property now differs, so the comparison prints False.
  4. Same as Subtract. dt.Add(-span) and dt.Subtract(span) give the same answer.

Example 3 — Roll into the Next Year

Add hours at the end of December and add a zero span.

C#
using System;
using System.Globalization;

class Program {
    static string Show(DateTime d) => d.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);

    static void Main() {
        DateTime nye = new DateTime(2026, 12, 31, 22, 0, 0);
        DateTime after = nye.Add(TimeSpan.FromHours(5));
        DateTime same = nye.Add(TimeSpan.Zero);
        Console.WriteLine(Show(after));
        Console.WriteLine(same == nye);
    }
}

How It Works

  1. New Year's Eve. The start value is December 31, 2026 at 22:00.
  2. Five hours later. The result crosses midnight and the year number changes to 2027.
  3. Zero span. TimeSpan.Zero adds nothing, so the new value equals the old one.
  4. Equality check. == compares ticks, so it prints True.

Frequently Asked Questions

No. DateTime is immutable. Add returns a new DateTime, so assign it to a variable to keep it.
Add takes a TimeSpan. AddDays takes a double number of days. Both return a new DateTime.
Yes. A negative TimeSpan moves the date backward.
No. Add works on ticks only. Use TimeZoneInfo conversions when you need daylight saving rules.
It throws ArgumentOutOfRangeException when the result is before DateTime.MinValue or after DateTime.MaxValue.

Next: AddDays()

Add or subtract a number of days and get a new DateTime with System.DateTime.

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

7 people found this page helpful