Skip to content
shellmap

Add or subtract days from a date

Compute a date offset from another date — e.g. "30 days from today" for expiry calculations, retention windows, and rolling reports.

How to add or subtract days from a date in each shell

Bashunix
date -d "+30 days"

GNU only. Accepts natural-language increments: `"+30 days"`, `"-1 week"`, `"next Friday"`, `"yesterday"`, `"1 month ago"`. Operating on a non-today base: `date -d "2026-01-01 +90 days"`.

Zshunix
date -d "+30 days"
Fishunix
date -d "+30 days"
PowerShellwindows
(Get-Date).AddDays(30)

Mirror methods: `AddYears`, `AddMonths`, `AddDays`, `AddHours`, `AddMinutes`, `AddSeconds`, `AddMilliseconds`, `AddTicks`. Subtraction: pass negative — `(Get-Date).AddDays(-7)`. Returns a `[DateTime]` you can chain: `(Get-Date).AddDays(30).AddHours(-2)`.

cmd.exewindows
powershell -NoProfile -Command "(Get-Date).AddDays(30).ToString('yyyy-MM-dd')"

cmd has no date arithmetic. `%date%` parsing-then-incrementing is brittle (locale-dependent, no month-length awareness, no leap-year handling). Always shell out.

Equivalents listed for Bash, Zsh, Fish, PowerShell, cmd.exe.

Gotchas & notes

  • **GNU vs BSD — totally different flag (`-d` vs `-v`)**: GNU (Linux) uses `date -d "+30 days"` (`-d` is "describe a date string", and the natural-language parser accepts `+N units` / `next Friday` / `last month` / etc.). BSD / macOS uses `date -v+30d` (the `-v` is "adjust" and takes a compact `<sign><N><unit>` spec where unit ∈ `y/m/w/d/H/M/S`). Cross-platform: `if [ "$(uname)" = "Darwin" ]; then date -v+30d; else date -d "+30 days"; fi`. Or `brew install coreutils` and use `gdate -d "+30 days"`. Both forms accept chaining: GNU `date -d "now +1 month +2 days"`; BSD `date -v+1m -v+2d`.
  • pwsh `(Get-Date).AddMonths(1)` is **calendar-aware** — adding 1 month to `Jan 31` returns `Feb 28` (or 29 in leap years), not `Feb 31` or `Mar 03`. GNU `date -d "+1 month"` on Jan 31 returns `Mar 03` (it adds 30/31 days, NOT calendar month). This is a real, surprising bug source — "monthly billing run" on Jan 31 silently shifts to Mar 03 with GNU date but stays Feb 28 with pwsh. For calendar-month arithmetic in bash: shell out to `python -c "from datetime import date; from dateutil.relativedelta import relativedelta; print(date.today() + relativedelta(months=1))"`. Or use pwsh in shell scripts: `pwsh -NoProfile -Command "(Get-Date).AddMonths(1).ToString('yyyy-MM-dd')"`.
  • Day-of-week arithmetic divergence: GNU `date -d "next Friday"` returns the NEXT occurrence after today (so "next Friday" on a Friday returns 7 days out). BSD `date -v+fri` returns the SOONEST upcoming Friday (so on a Friday it returns... opinion divided across BSD vintages — modern macOS returns the same day, older BSD returns 7 days out). Don't rely on natural-language week-day math for date-critical logic — compute the offset to the target day-of-week first, then use the unambiguous `+N days` form. pwsh: `$daysUntilFriday = ([DayOfWeek]::Friday - (Get-Date).DayOfWeek + 7) % 7`.
  • Common pitfalls: (1) DST transitions — adding 24h (`+86400 seconds`) crosses a DST boundary differently from adding 1 calendar day. Use `AddDays(1)` (pwsh) or `+1 day` (GNU date) for calendar semantics; `+86400 seconds` for absolute seconds. (2) Negative dates underflow — `date -d "1970-01-01 -1 day"` gives `1969-12-31` on GNU but `[DateTimeOffset]::FromUnixTimeSeconds(-86400)` works on pwsh too. (3) `AddDays(1.5)` in pwsh is valid (half-day increment) — `date -d "+1.5 days"` is NOT (GNU rejects fractional units).

Related commands

Related tasks