Add hours to a DateTime : Date Time Calculation « Date Time « C# / C Sharp






Add hours to a DateTime

    

using System;

public class Example
{
   public static void Main()
   {
      DateTime dateValue = new DateTime(2009, 3, 1, 12, 0, 0);

      Console.WriteLine(dateValue.AddHours(0.001));
      Console.WriteLine(dateValue.AddHours(0.0));
      Console.WriteLine(dateValue.AddHours(1.1));
      Console.WriteLine(dateValue.AddHours(0.25));
      Console.WriteLine(dateValue.AddHours(0.6667));

   }
}

   
    
    
    
  








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 two DateTime value together
10.Add milliseconds to DateTime