use the AddYears(), AddMonths(), AddDays(), AddMinutes(), and AddSeconds() methods to add periods to a DateTime : Date Time Calculation « Date Time « C# / C Sharp






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

1.Add 2 month to the date time
2.Add TimeSpan to DateTime
3.use the Add() method to add a TimeSpan to a DateTime
4.use the overloaded addition operator (+) to add a TimeSpan to a DateTime
5.Measures the time taken to add some numbersMeasures the time taken to add some numbers
6.Add TimeSpan to a new DateTime
7.Add the specified number of days to a DateTime
8.Add hours to a DateTime
9.Add two DateTime value together
10.Add milliseconds to DateTime