[edit] Using the DateTime.AddYears Method
To use the DateTime.AddYears method you will not specify a timespan. You must specify the amount of ticks you want to add. It accepts an int value so it can NOT calculate partial years. Remember, a timespan must NOT be used with DateTime.AddYears.
[edit] Syntax
DateTime.AddYears(<int>)
[edit] Example 1:
using System;
class Program
{
static void Main()
{
DateTime today = DateTime.Now;
Console.WriteLine("today: " + today.ToString());
today = today.AddYears(6);
Console.WriteLine("New Date: " + today.ToString());
Console.Read();
}
}
Output:
today: 4/5/2007 8:28:51 PM
New Date: 4/5/2013 8:28:51 PM
As you can see the AddYears method simply added 6 years to the current date.
<-- DateTime Tutorial
|