Bash

Add / Subtract Time from Date

admin by @admin ADMIN
Jun 19, 2026
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
GNU date accepts natural-language deltas: "+1 day", "-3 weeks", "now + 2 hours". Combine with -d to compute against any reference date.
Bash
Raw
# Tomorrow / yesterday
date -d "tomorrow" +%F             # 2025-03-13
date -d "yesterday" +%F            # 2025-03-11

# N units from now
date -d "+7 days" +%F              # one week from today
date -d "-2 weeks" +%F             # two weeks ago
date -d "+3 months" +%F            # three months from today

# From a specific date
date -d "2025-01-01 +30 days" +%F  # 2025-01-31

# Same with a Unix timestamp result
date -d "2025-01-01 +30 days" +%s

# macOS / BSD date — different syntax (uses -v)
date -v +7d +%F                    # 7 days from now
date -v -1m +%F                    # 1 month ago
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.