Add two DateTime value together : Date Time Calculation « Date Time « C# / C Sharp






Add two DateTime value together

    

using System;
using System.Globalization;

class Sample 
{
    public static void Main() 
    {
      System.DateTime dTime = new System.DateTime(1980, 8, 5);

      // tSpan is 17 days, 4 hours, 2 minutes and 1 second.
      System.TimeSpan tSpan 
        = new System.TimeSpan(17, 4, 2, 1); 

      // Result gets 8/22/1980 4:02:01 AM.
      System.DateTime result = dTime + tSpan;
    }
}

   
    
    
    
  








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.use the AddYears(), AddMonths(), AddDays(), AddMinutes(), and AddSeconds() methods to add periods to a DateTime
6.Measures the time taken to add some numbersMeasures the time taken to add some numbers
7.Add TimeSpan to a new DateTime
8.Add the specified number of days to a DateTime
9.Add hours to a DateTime
10.Add milliseconds to DateTime