How to Add Seconds and Milliseconds to a DateTime in C#
start.AddSeconds(12.5) gives the time 12.5 seconds after start, and AddMilliseconds(250) adds a quarter of a second. Both take fractions and negative numbers, and both hand you a new DateTime instead of changing the one you call them on.
A DateTime holds a date and a time of day. AddSeconds and AddMilliseconds are two of its methods for moving that time forward or back. Microsoft's API reference describes them this way: Returns a new DateTime that adds the specified number of seconds to the value of this instance. And: Returns a new DateTime that adds the specified number of milliseconds to the value of this instance.
The word "new" matters. The reference adds: This method does not change the value of this DateTime. Instead, it returns a new DateTime whose value is the result of this operation.
Syntax
DateTime <later> = <time>.AddSeconds(<seconds>);
DateTime <later> = <time>.AddMilliseconds(<milliseconds>);
| Part | What it is |
|---|---|
<time> | The DateTime you start from. It stays as it is |
AddSeconds | Adds a number of seconds |
<seconds> | A double: whole and fractional seconds, such as 12.5. A negative number goes back in time |
AddMilliseconds | Adds a number of milliseconds, the thousandths of a second |
<milliseconds> | A double: whole and fractional milliseconds, such as 250 |
<later> | The new DateTime that the method returns |
The Example
A console app called AddSecondsMilliseconds times a race. The race starts at exactly 10:00 UTC. The first runner finishes 12.5 seconds later, and the second runner 250 milliseconds after the first. There's also a ready signal 3 seconds before the start. The app prints every time down to the millisecond.
Prerequisites
- The .NET 10 SDK.
dotnet --versionprints a version that starts with10.0.
Step 1: Create a Console App
dotnet new console -n AddSecondsMilliseconds
cd AddSecondsMilliseconds
The template "Console App" was created successfully.
Processing post-creation actions...
Restoring /Users/you/source/AddSecondsMilliseconds/AddSecondsMilliseconds.csproj:
Determining projects to restore...
Restored /Users/you/source/AddSecondsMilliseconds/AddSecondsMilliseconds.csproj (in 48 ms).
Restore succeeded.
dotnet new console -n AddSecondsMilliseconds creates a folder named AddSecondsMilliseconds with a project file and a Program.cs, and cd moves into it. Everything this example uses is part of .NET, so there's no package to add. Open the folder in VS Code, or AddSecondsMilliseconds.csproj in Visual Studio.
Step 2: Write the Code
Replace everything in Program.cs. First the start time:
// A race starts at exactly 10:00 UTC. HH:mm:ss.fff shows the time down to the millisecond.
DateTime start = new DateTime(2026, 12, 3, 10, 0, 0, DateTimeKind.Utc);
Console.WriteLine($"Start: {start:HH:mm:ss.fff}");
new DateTime(2026, 12, 3, 10, 0, 0, DateTimeKind.Utc) is 10:00:00 on 3 December 2026, marked as a UTC time. In {start:HH:mm:ss.fff}, everything after start: is a format: hours, minutes, seconds and, after the dot, fff. Microsoft's format reference: The "fff" custom format specifier represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value.
Then AddSeconds with a fraction:
// AddSeconds takes whole and fractional seconds: 12.5 is 12 seconds and 500 milliseconds.
DateTime first = start.AddSeconds(12.5);
Console.WriteLine($"First runner: {first:HH:mm:ss.fff}");
start.AddSeconds(12.5) returns the time 12.5 seconds after start, and first keeps it. The reference explains the fraction: The fractional part of value is the fractional part of a second. For example, 4.5 is equivalent to 4 seconds, 500 milliseconds, and 0 ticks.
Then AddMilliseconds:
// AddMilliseconds adds thousandths of a second: the second runner is 250 ms behind.
DateTime second = first.AddMilliseconds(250);
Console.WriteLine($"Second runner: {second:HH:mm:ss.fff}");
This call starts from first, the first runner's time, and adds 250 milliseconds to it.
Then a negative number:
// A negative number goes back in time.
DateTime ready = start.AddSeconds(-3);
Console.WriteLine($"Ready signal: {ready:HH:mm:ss.fff}");
AddSeconds(-3) gives the time 3 seconds before the start. The reference: The value parameter can be negative or positive.
Last, start once more:
// Each call returns a new DateTime, so start itself hasn't changed.
Console.WriteLine($"Start is still: {start:HH:mm:ss.fff}");
Console.WriteLine($"Second runner's time: {(second - start).TotalSeconds} seconds");
None of the calls changed start. second - start is the time between the start and the second runner, and TotalSeconds gives it as a number of seconds.
Step 3: Run It
Run it in VS Code's terminal, or press Ctrl+F5 in Visual Studio:
dotnet run
Start: 10:00:00.000
First runner: 10:00:12.500
Second runner: 10:00:12.750
Ready signal: 09:59:57.000
Start is still: 10:00:00.000
Second runner's time: 12.75 seconds

The first runner finished at 10:00:12.500, 12.5 seconds after the start, and the second runner at 10:00:12.750, 250 milliseconds later. The ready signal printed 09:59:57.000, 3 seconds before 10:00. After all those calls, start still printed 10:00:00.000, because each method returned a new DateTime. The second runner's time came to 12.75 seconds.
The Complete File

// A race starts at exactly 10:00 UTC. HH:mm:ss.fff shows the time down to the millisecond.
DateTime start = new DateTime(2026, 12, 3, 10, 0, 0, DateTimeKind.Utc);
Console.WriteLine($"Start: {start:HH:mm:ss.fff}");
// AddSeconds takes whole and fractional seconds: 12.5 is 12 seconds and 500 milliseconds.
DateTime first = start.AddSeconds(12.5);
Console.WriteLine($"First runner: {first:HH:mm:ss.fff}");
// AddMilliseconds adds thousandths of a second: the second runner is 250 ms behind.
DateTime second = first.AddMilliseconds(250);
Console.WriteLine($"Second runner: {second:HH:mm:ss.fff}");
// A negative number goes back in time.
DateTime ready = start.AddSeconds(-3);
Console.WriteLine($"Ready signal: {ready:HH:mm:ss.fff}");
// Each call returns a new DateTime, so start itself hasn't changed.
Console.WriteLine($"Start is still: {start:HH:mm:ss.fff}");
Console.WriteLine($"Second runner's time: {(second - start).TotalSeconds} seconds");
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Passing milliseconds to AddSeconds | start.AddSeconds(500) printed 10:08:20.000, more than 8 minutes after the start instead of half a second | Use AddMilliseconds(500), which printed 10:00:00.500 |
Turning milliseconds into seconds with delay / 1000 when delay is an int | With delay set to 1500, delay / 1000 was 1, so AddSeconds(delay / 1000) printed 10:00:01.000 and lost half a second | Use AddMilliseconds(delay), or divide by 1000.0: both printed 10:00:01.500 |
Calling start.AddSeconds(30); on its own line | start still printed 10:00:00.000, and the build gave no warning | Keep the result: after start = start.AddSeconds(30);, start printed 10:00:30.000 |
Printing with HH:mm:ss | 10:00:12.500 and 10:00:12.750 both printed as 10:00:12, although first == second was False | Add .fff to see the milliseconds |
FAQ
Does AddMilliseconds keep a fraction of a millisecond?
Yes, on .NET 10. AddMilliseconds(1.5) printed 10:00:00.0015000 with the seven-digit format fffffff, and the time moved by 15000 ticks. The API reference: A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, and: In .NET 7 and later versions, the full Double precision of the value parameter is used. However, due to the inherent imprecision of floating point math, the resulting precision will vary. The same page's note on the value parameter still says that the value is rounded to the nearest integer. I reported the mismatch to the .NET API docs as issue #13410.
How do I add microseconds?
With AddMicroseconds, which .NET 7 added. The reference: Returns a new DateTime that adds the specified number of microseconds to the value of this instance. start.AddMicroseconds(250) printed 10:00:00.000250 with the six-digit format ffffff.
What if the result is too far in the past or the future?
You get an ArgumentOutOfRangeException. DateTime.MaxValue.AddSeconds(1) threw one with the message The added or subtracted value results in an un-representable DateTime. (Parameter 'value'). The reference lists it for this case: The resulting DateTime is less than DateTime.MinValue or greater than DateTime.MaxValue.
Conclusion
AddSeconds and AddMilliseconds move a DateTime by seconds or milliseconds: forward with a positive number, back with a negative one, and with fractions such as 12.5. They return a new DateTime, so keep the result in a variable, and print with .fff when the milliseconds matter.
Additional Resources
- DateTime.AddSeconds — the method, its fractions and its exception.
- DateTime.AddMilliseconds — adding thousandths of a second.
- DateTime.AddMicroseconds — adding millionths of a second.
- Custom date and time format strings —
HH,mm,ss,fffand the other format letters.
