C# DateTime AddSeconds() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DateTime

Definition

In C#, DateTime.AddSeconds shifts a value by seconds. The parameter is a double, so 0.5 means half a second.

Use it for countdowns, expiry times, and token lifetimes. Large values are fine: 86,400 seconds is exactly one day.

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

Syntax

Pass the number of seconds to add.

C#
DateTime dt = new DateTime(2026, 11, 18, 14, 30, 45);
DateTime a = dt.AddSeconds(30);      // 14:31:15
DateTime b = dt.AddSeconds(-46);     // 14:29:59
DateTime c = dt.AddSeconds(86400);   // next day, same time
CallWhat it does
dt.AddSeconds(30)Thirty seconds later; the minute changes.
dt.AddSeconds(-46)Forty-six seconds earlier.
dt.AddSeconds(86400)Exactly one day later.

AddSeconds(3600) equals AddHours(1). All Add methods return a new value and leave the original unchanged.

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

Parameters

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

Return Value

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

C# Examples

Example 1 — Shift by Seconds

Add 30 seconds and subtract 46 seconds from a fixed time.

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.AddSeconds(30)));
        Console.WriteLine(Show(dt.AddSeconds(-46)));
    }
}

How It Works

  1. Plus 30. 14:30:45 plus 30 seconds carries into the next minute, 14:31:15.
  2. Minus 46. 45 seconds minus 46 goes below zero and borrows a minute.
  3. Result 14:29:59. One second before 14:30:00 is the answer.
  4. Carry works both ways. You never fix minutes by hand; the type does it.

Example 2 — 3600 and 86400 Seconds

Show that seconds can express an hour and a whole day.

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(dt.AddSeconds(3600) == dt.AddHours(1));
        Console.WriteLine(Show(dt.AddSeconds(86400)));
    }
}

How It Works

  1. One hour. An hour has 3600 seconds, so both calls land on the same instant.
  2. Equality is by ticks. == compares the exact moment, so it prints True.
  3. One day. 86,400 seconds moves to the same time on November 19.
  4. Pick the readable one. Use AddHours or AddDays when it makes the code clearer.

Example 3 — Fractions of a Second

Add 90 seconds and half a second to midnight.

C#
using System;
using System.Globalization;

class Program {
    static void Main() {
        DateTime midnight = new DateTime(2026, 11, 18, 0, 0, 0);
        DateTime a = midnight.AddSeconds(90);
        DateTime b = midnight.AddSeconds(0.5);
        Console.WriteLine(a.ToString("HH:mm:ss", CultureInfo.InvariantCulture));
        Console.WriteLine(b.ToString("HH:mm:ss.fff", CultureInfo.InvariantCulture));
    }
}

How It Works

  1. Start at midnight. Every value is easy to read from 00:00:00.
  2. 90 seconds. That is one minute and thirty seconds, shown as 00:01:30.
  3. 0.5 seconds. A fraction is allowed because the parameter is a double.
  4. fff format. The second line uses .fff so the half second becomes .500.

Frequently Asked Questions

Yes. AddSeconds(0.5) adds half a second.
Yes. Both give the same DateTime.
Use DateTime.UtcNow.AddSeconds(n). Store it as UTC so every server agrees.
No. DateTime ignores leap seconds. Each second is the same length.
No. DateTime is immutable. Use the returned value.

Next: AddTicks()

Add or subtract raw ticks (100 ns steps) and get a new DateTime with System.DateTime.

AddTicks() 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.

13 people found this page helpful