C# DateTime AddMonths() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DateTime

Definition

In C#, DateTime.AddMonths moves a date by whole months. A positive number goes forward and a negative number goes back. The time of day stays the same.

If the target month is shorter than the day number, the day is clamped to the last day of that month. So January 31 plus one month is February 28 (or 29 in a leap year).

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

Syntax

Pass a whole number of months (an int).

C#
DateTime d = new DateTime(2026, 11, 18);
DateTime a = d.AddMonths(3);     // 2027-02-18
DateTime b = d.AddMonths(-11);   // 2025-12-18
DateTime c = new DateTime(2026, 1, 31).AddMonths(1);   // 2026-02-28
CallWhat it does
d.AddMonths(3)Three months later; year changes if needed.
d.AddMonths(-11)Eleven months earlier.
new DateTime(2026, 1, 31).AddMonths(1)Day is clamped to the last day of February.

The argument is an int, so fractional months are not allowed. Chaining AddMonths(1) twice is not the same as AddMonths(2) when the day is 29, 30, or 31.

Library declarations
C#
public DateTime AddMonths(int months);

Parameters

ParameterDescription
monthsRequired. Whole number of months to add. Negative values go backward.

Return Value

Return ValueDescription
DateTimeA new DateTime. The day is clamped to the number of days in the target month.

C# Examples

Example 1 — Add and Subtract Months

Move a date across a year boundary in both directions.

C#
using System;
using System.Globalization;

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

    static void Main() {
        DateTime d = new DateTime(2026, 11, 18);
        Console.WriteLine(Day(d.AddMonths(3)));
        Console.WriteLine(Day(d.AddMonths(-11)));
    }
}

How It Works

  1. Plus three. November plus 3 months wraps to February of the next year.
  2. Year increases. The year changes from 2026 to 2027 by itself.
  3. Minus eleven. Going back 11 months from November 2026 reaches December 2025.
  4. Day is kept. The day number stays 18 because both target months have at least 18 days.

Example 2 — Jan 31 and Short Months

See how the day shrinks in February, including 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() {
        Console.WriteLine(Day(new DateTime(2026, 1, 31).AddMonths(1)));
        Console.WriteLine(Day(new DateTime(2028, 1, 31).AddMonths(1)));
        Console.WriteLine(Day(new DateTime(2026, 3, 31).AddMonths(-1)));
    }
}

How It Works

  1. Normal year. February 2026 has 28 days, so day 31 is clamped to 28.
  2. Leap year. February 2028 has 29 days, so the same call gives the 29th.
  3. Going backward. March 31 minus one month also lands on the last day of February.
  4. No exception. The method never fails for a short month; it just picks the last valid day.

Example 3 — Monthly Billing Dates

Build three billing dates from one start date on January 31.

C#
using System;
using System.Globalization;

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

    static void Main() {
        DateTime start = new DateTime(2026, 1, 31);
        for (int i = 1; i <= 3; i++) {
            Console.WriteLine(Day(start.AddMonths(i)));
        }
    }
}

How It Works

  1. One fixed start. Every line is computed from January 31, not from the previous result.
  2. February. Month 1 is clamped to February 28.
  3. March recovers. Month 2 from the original start is March 31 again.
  4. April. Month 3 has only 30 days, so the day is clamped to April 30.

Frequently Asked Questions

It clamps the day. January 31 plus one month is February 28, or February 29 in a leap year.
No. The parameter is an int. Use AddDays for smaller steps.
Yes. Only the year, month, and possibly the day change.
Not always. Jan 31 + 1 + 1 months gives Mar 28, but Jan 31 + 2 months gives Mar 31.
Use new DateTime(y, m, 1).AddMonths(2).AddDays(-1), or DateTime.DaysInMonth.

Next: AddSeconds()

Add or subtract seconds (fractions allowed) and get a new DateTime with System.DateTime.

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

12 people found this page helpful