In C#, DateTime.AddYears moves a date by whole years. A negative number goes back. Month, day, and time stay the same.
The only special case is February 29. If the target year is not a leap year, the day becomes February 28.
This is an instance member of System.DateTime. You call it on a DateTime value, such as dt.AddYears(...). DateTime is a struct, so every value is copied and never changed in place.
Syntax
Pass a whole number of years (an int).
C#
DateTime d = new DateTime(2026, 11, 18);
DateTime a = d.AddYears(5); // 2031-11-18
DateTime b = d.AddYears(-26); // 2000-11-18
DateTime c = new DateTime(2028, 2, 29).AddYears(1); // 2029-02-28
Call
What it does
d.AddYears(5)
Five years later, same month and day.
d.AddYears(-26)
Twenty-six years earlier.
new DateTime(2028, 2, 29).AddYears(1)
Leap day becomes February 28 in 2029.
The argument is an int. The result must stay within years 1 to 9999, or ArgumentOutOfRangeException is thrown.
Library declarations
C#
public DateTime AddYears(int value);
Parameters
Parameter
Description
value
Required. Whole number of years to add. Negative values go backward.
Return Value
Return Value
Description
DateTime
A new DateTime in the target year. February 29 is moved to February 28 if needed.
C# Examples
Example 1 — Add and Subtract Years
Move a date five years ahead and 26 years back.
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.AddYears(5)));
Console.WriteLine(Day(d.AddYears(-26)));
}
}
Output
2031-11-18
2000-11-18
How It Works
Plus five. Only the year number changes: 2026 becomes 2031.
Minus 26. A negative value reaches the year 2000.
Month and day stay. Both results keep November 18.
Date only. The helper prints the date and hides the midnight time.
Example 2 — February 29
Add one year and four years to a leap day.
C#
using System;
using System.Globalization;
class Program {
static string Day(DateTime d) => d.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
static void Main() {
DateTime leapDay = new DateTime(2028, 2, 29);
Console.WriteLine(Day(leapDay.AddYears(1)));
Console.WriteLine(Day(leapDay.AddYears(4)));
}
}
Output
2029-02-28
2032-02-29
How It Works
2029 is not a leap year. February 29 does not exist, so the day becomes 28.
2032 is a leap year. Four years later February 29 exists again.
No exception. The method picks the nearest valid day instead of failing.
Compare steps. Adding four single years would end at the 28th, not the 29th.
Example 3 — Compute an Age
Use AddYears to find a full age and the next birthday.
C#
using System;
using System.Globalization;
class Program {
static void Main() {
DateTime birth = new DateTime(1990, 5, 15);
DateTime today = new DateTime(2026, 11, 18);
int age = today.Year - birth.Year;
if (birth.AddYears(age) > today) age--;
Console.WriteLine(age);
Console.WriteLine(birth.AddYears(age + 1).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
}
}
Output
36
2027-05-15
How It Works
Fixed "today". The code uses November 18, 2026 so the answer never changes.
First guess. 2026 minus 1990 is 36 years.
Birthday check.birth.AddYears(36) is May 15, 2026, which is not after today, so age stays 36.
Next birthday.AddYears(age + 1) returns May 15, 2027.
Frequently Asked Questions
If the target year is not a leap year, the date becomes February 28.
Yes. AddYears(-1) returns the same date one year earlier.
Subtract the years, then subtract one more if birth.AddYears(age) is after today.
Yes. Only the year (and possibly Feb 29) can change.
No. DateTime is immutable. Use the returned value.