use the AddYears(), AddMonths(), AddDays(), AddMinutes(), and AddSeconds() methods to add periods to a DateTime
using System;
class MainClass {
public static void Main() {
DateTime myDateTime9 = new DateTime(2004, 1, 1);
Console.WriteLine("Initial myDateTime9 = " + myDateTime9);
myDateTime9 = myDateTime9.AddYears(1);
myDateTime9 = myDateTime9.AddMonths(5);
myDateTime9 = myDateTime9.AddDays(3);
myDateTime9 = myDateTime9.AddMinutes(30);
myDateTime9 = myDateTime9.AddSeconds(15);
Console.WriteLine("Final myDateTime9 = " + myDateTime9);
}
}
Related examples in the same category