C# DateTime AddHours() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DateTime

Definition

In C#, DateTime.AddHours shifts a value by a number of hours. The argument is a double, so 0.5 means thirty minutes and -3 means three hours earlier.

If the hours cross midnight, the date part changes too. The method does not know about time zones, so it is plain clock arithmetic.

This is an instance member of System.DateTime. You call it on a DateTime value, such as dt.AddHours(...). DateTime is a struct, so every value is copied and never changed in place.

Syntax

Pass a number of hours to AddHours.

C#
DateTime dt = new DateTime(2026, 11, 18, 14, 30, 45);
DateTime a = dt.AddHours(3);      // 17:30:45
DateTime b = dt.AddHours(-15);    // previous day 23:30:45
DateTime c = dt.AddHours(0.5);    // 15:00:45
CallWhat it does
dt.AddHours(3)Three hours later.
dt.AddHours(-15)Fifteen hours earlier, which crosses midnight.
dt.AddHours(0.5)Half an hour later.

AddHours(2) gives the same result as Add(TimeSpan.FromHours(2)). Use ToUniversalTime or TimeZoneInfo when real time zone rules matter.

Library declarations
C#
public DateTime AddHours(double value);

Parameters

ParameterDescription
valueRequired. Number of hours to add. Negative values go backward; fractions are allowed.

Return Value

Return ValueDescription
DateTimeA new DateTime shifted by value hours, with the same Kind.

C# Examples

Example 1 — Shift by Whole Hours

Add three hours, then subtract fifteen hours across midnight.

C#
using System;
using System.Globalization;

class Program {
    static string Show(DateTime d) => d.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);

    static void Main() {
        DateTime dt = new DateTime(2026, 11, 18, 14, 30, 45);
        Console.WriteLine(Show(dt.AddHours(3)));
        Console.WriteLine(Show(dt.AddHours(-15)));
    }
}

How It Works

  1. Three hours on. 14:30:45 becomes 17:30:45 on the same day.
  2. Fifteen hours back. 14:30:45 minus 15 hours is half an hour before midnight.
  3. Date changes. The second result belongs to November 17 because the clock crossed midnight.
  4. Minutes and seconds. They stay 30 and 45 because only whole hours moved.

Example 2 — Fractions and Long Shifts

Add half an hour and then more than a full day of hours.

C#
using System;
using System.Globalization;

class Program {
    static string Show(DateTime d) => d.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);

    static void Main() {
        DateTime dt = new DateTime(2026, 11, 18, 14, 30, 45);
        Console.WriteLine(Show(dt.AddHours(0.5)));
        Console.WriteLine(Show(dt.AddHours(25)));
    }
}

How It Works

  1. 0.5 hours. Thirty minutes later moves 14:30:45 to 15:00:45.
  2. 25 hours. One full day plus one hour gives the next day at 15:30:45.
  3. No limit at 24. You can pass any size; the date rolls over as many times as needed.
  4. Still new values. Both lines come from fresh DateTime results; dt itself is the same.

Example 3 — Shift a UTC Time

Add 5.5 hours to a UTC time and compare AddHours with Add.

C#
using System;
using System.Globalization;

class Program {
    static string Show(DateTime d) => d.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);

    static void Main() {
        DateTime utc = new DateTime(2026, 11, 18, 9, 0, 0, DateTimeKind.Utc);
        DateTime ist = utc.AddHours(5.5);
        Console.WriteLine(Show(ist));
        Console.WriteLine(utc.AddHours(2) == utc.Add(TimeSpan.FromHours(2)));
    }
}

How It Works

  1. UTC start. The value is 09:00 with Kind set to Utc.
  2. Plus 5.5 hours. India Standard Time is UTC+05:30, so the clock shows 14:30.
  3. Simple arithmetic. The result keeps Kind.Utc; it is only a shifted number, not a real zone conversion.
  4. Same as Add. AddHours(2) equals Add(TimeSpan.FromHours(2)), so the check prints True.

Frequently Asked Questions

Yes. AddHours(0.5) adds thirty minutes and AddHours(1.25) adds one hour fifteen minutes.
Yes, when the hours cross midnight the date part moves forward or back.
Yes. They produce the same value. AddHours is just shorter.
No. It adds exact hours to the clock value. Use TimeZoneInfo for time zone rules.
No. DateTime is immutable, so you must use the returned value.

Next: AddMilliseconds()

Add or subtract milliseconds and get a new DateTime with System.DateTime.

AddMilliseconds() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful