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
Call
What 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
Parameter
Description
months
Required. Whole number of months to add. Negative values go backward.
Return Value
Return Value
Description
DateTime
A 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)));
}
}
Output
2027-02-18
2025-12-18
How It Works
Plus three. November plus 3 months wraps to February of the next year.
Year increases. The year changes from 2026 to 2027 by itself.
Minus eleven. Going back 11 months from November 2026 reaches December 2025.
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)));
}
}
Output
2026-02-28
2028-02-29
2026-02-28
How It Works
Normal year. February 2026 has 28 days, so day 31 is clamped to 28.
Leap year. February 2028 has 29 days, so the same call gives the 29th.
Going backward. March 31 minus one month also lands on the last day of February.
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)));
}
}
}
Output
2026-02-28
2026-03-31
2026-04-30
How It Works
One fixed start. Every line is computed from January 31, not from the previous result.
February. Month 1 is clamped to February 28.
March recovers. Month 2 from the original start is March 31 again.
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.