How to Add Minutes to a Time in Go
In Go, a length of time is a time.Duration, and the package gives you constants such as time.Minute to build one. t.Add(15 * time.Minute) returns the time 15 minutes later; later.Sub(t) gives the gap back.
Syntax
<later> := <t>.Add(<n> * time.Minute)
<gap> := <later>.Sub(<t>)
| Part | What it does |
|---|---|
<n> * time.Minute | A time.Duration of <n> minutes. There are also time.Second and time.Hour. |
<t>.Add(...) | Returns a new time.Time; <t> itself doesn't change. |
<later>.Sub(<t>) | The time.Duration between the two times. |
The time package documentation: "Add returns the time t+d." And for Sub: "Sub returns the duration t-u."
The Example
The example starts at 09:30 UTC on 26 November 2026, adds 15 minutes and prints the new time and the gap.
Prerequisites
- Go.
go runcompiles and runs a single file. This guide uses Go 1.27.4.
Step 1: Write the Code
Create a file named main.go:

package main
import (
"fmt"
"time"
)
func main() {
start := time.Date(2026, 11, 26, 9, 30, 0, 0, time.UTC)
end := start.Add(15 * time.Minute)
fmt.Println(end)
fmt.Println(end.Sub(start))
}
time.Date builds a time from its parts: year, month, day, hour, minute, second, nanosecond and location.
Step 2: Run It
go run main.go
2026-11-26 09:45:00 +0000 UTC
15m0s

The command is the same in zsh, bash and PowerShell.
Watch the Unit
A time.Duration counts nanoseconds. start.Add(15) compiles, but it adds 15 nanoseconds: it printed 2026-11-26 09:30:00.000000015 +0000 UTC. Always multiply by a unit such as time.Minute.
When the number of minutes is in an int variable, convert it first: time.Duration(minutes) * time.Minute gave 15m0s, while time.Minute * minutes doesn't compile.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
start.Add(15) | Adds 15 nanoseconds | start.Add(15 * time.Minute) |
Multiplying a Duration by an int variable | invalid operation: time.Minute * m (mismatched types time.Duration and int) | Convert: time.Duration(m) * time.Minute |
Calling start.Add(...) without keeping the result | start doesn't change; the new time is lost | Assign the result |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| A time moved by nanoseconds instead of minutes | A plain number was passed to Add | Multiply by time.Minute |
mismatched types time.Duration and int | An int variable met a Duration | Wrap it in time.Duration(...) |
FAQ
How do I go back in time?
Add a negative duration: t.Add(-15 * time.Minute).
How do I add days or months?
t.AddDate(0, 1, 0) adds one month; AddDate takes years, months and days.
Conclusion
t.Add(15 * time.Minute) returns the time 15 minutes later and later.Sub(t) gives the gap. Always multiply by a unit, because a bare number means nanoseconds.
Additional Resources
- time.Time.Add, in the Go standard library documentation.
- time.Duration, in the Go standard library documentation.
