C# DateTime AddDays() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DateTime

Definition

In C#, DateTime.AddDays moves a date forward by a number of days. Use a negative number to go back. The number is a double, so 1.5 means one and a half days.

The method follows the real calendar: it rolls over month ends and understands leap years. The time of day stays the same unless you add a fraction.

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

Syntax

Call AddDays on a DateTime and pass the number of days.

C#
DateTime dt = new DateTime(2026, 11, 18, 14, 30, 45);
DateTime a = dt.AddDays(10);    // 2026-11-28
DateTime b = dt.AddDays(-18);   // 2026-10-31
DateTime c = dt.AddDays(1.5);   // adds 36 hours
CallWhat it does
dt.AddDays(10)Ten days later, same time of day.
dt.AddDays(-18)Eighteen days earlier.
dt.AddDays(1.5)One day and twelve hours later.

Fractions are allowed. AddDays(0.25) adds six hours. For whole calendar months or years use AddMonths or AddYears instead.

Library declarations
C#
public DateTime AddDays(double value);

Parameters

ParameterDescription
valueRequired. Number of days to add. Negative values go backward; fractions are allowed.

Return Value

Return ValueDescription
DateTimeA new DateTime that is value days away. The Kind is kept.

C# Examples

Example 1 — Add and Subtract Days

Show a forward move, a backward move, and the unchanged original.

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);
        Console.WriteLine(Show(dt.AddDays(10)));
        Console.WriteLine(Show(dt.AddDays(-18)));
        Console.WriteLine(Show(dt));
    }
}

How It Works

  1. Plus ten. November 18 plus 10 days is November 28.
  2. Minus eighteen. Going back 18 days crosses the month border into October 31.
  3. Time kept. Whole days never change the 14:30:45 time of day.
  4. Original intact. The last line proves dt was not modified.

Example 2 — Add 1.5 Days

Use a fractional number to move by a day and a half.

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 later = dt.AddDays(1.5);
        Console.WriteLine(Show(later));
        Console.WriteLine((later - dt).TotalHours);
    }
}

How It Works

  1. 1.5 days. That is 24 hours plus 12 hours, or 36 hours in total.
  2. Cross midnight twice. 14:30:45 plus 36 hours lands at 02:30:45 two calendar days later.
  3. Measure the gap. Subtracting two DateTime values gives a TimeSpan.
  4. TotalHours. It prints 36, which confirms the fraction was applied exactly.

Example 3 — Leap Day Check

Add two days near the end of February in a normal year and in a leap year.

C#
using System;
using System.Globalization;

class Program {
    static string Day(DateTime d) => d.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);

    static void Main() {
        DateTime normal = new DateTime(2026, 2, 27);
        DateTime leap = new DateTime(2028, 2, 27);
        Console.WriteLine(Day(normal.AddDays(2)));
        Console.WriteLine(Day(leap.AddDays(2)));
    }
}

How It Works

  1. 2026 is normal. February has 28 days, so two days after Feb 27 is March 1.
  2. 2028 is a leap year. February has 29 days, so the same step lands on Feb 29.
  3. Calendar aware. You do not write any leap-year logic; AddDays does it.
  4. Date only. The Day helper prints yyyy-MM-dd and hides the time.

Frequently Asked Questions

Yes. AddDays(-1) returns the previous day.
Not for whole numbers. A fractional value such as 0.5 adds hours, so the time changes.
Yes. It uses the real calendar, so Feb 27 plus 2 days is Feb 29 in 2028 and March 1 in 2026.
DateTime is immutable. Assign the result: dt = dt.AddDays(1).
AddDays only counts calendar days. For business days loop with AddDays(1) and skip Saturday and Sunday.

Next: AddHours()

Add or subtract hours (including fractions) and get a new DateTime with System.DateTime.

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

8 people found this page helpful