Skip to content
shellmap

datePrint the current date and time, or format an arbitrary date across all 5 shells

Equivalents in every shell

Bashunix
date

External binary from coreutils. `date` (no args) prints in your locale's default format. `date +"%Y-%m-%d"` for ISO date; `date -u +"%Y-%m-%dT%H:%M:%SZ"` for ISO-8601 UTC (the canonical machine-readable form). `date -d "yesterday"` (GNU, Linux only) computes relative dates; macOS BSD `date` uses `date -v-1d` for the same. `date +%s` is the Unix epoch in seconds. Set the date (requires root): `date -s "2026-05-16 12:00:00"`.

Zshunix
date

Same external. macOS ships BSD `date`, Linux ships GNU `date` — the FLAG SYNTAX differs significantly. `date -d "next friday"` works on GNU only. `date -v+1d` works on BSD/macOS only. The output formatting (`+"%Y-%m-%d"`) IS portable. Zsh built-in `print -P "%D{%Y-%m-%d}"` does date formatting without a fork — fast but locked to the current time only (no arbitrary-date arithmetic).

Fishunix
date

Same external. Fish-specific extras: `$date_now` is NOT a built-in — fish prefers explicit invocation. For substitution: `set today (date +%Y-%m-%d)` captures into a variable. Fish lacks bash's `${EPOCHSECONDS}` magic var; use `date +%s` and capture.

PowerShellwindows
Get-Date

Returns a rich `[DateTime]` object, not a string — `(Get-Date).Year`, `(Get-Date).DayOfWeek`, `(Get-Date).AddDays(-7)` all work directly. Format: `Get-Date -Format "yyyy-MM-dd"` (.NET format strings, NOT strftime); `Get-Date -Format "o"` for ISO-8601 with sub-second precision and timezone offset. UTC: `(Get-Date).ToUniversalTime()` or `[DateTime]::UtcNow`. Epoch: `[DateTimeOffset]::Now.ToUnixTimeSeconds()`. Parse: `[DateTime]::Parse("2026-05-16")` or `[DateTime]::ParseExact("2026-05-16","yyyy-MM-dd",$null)`.

cmd.exewindows
date /T

`date /T` prints the date without prompting; `time /T` for the time. Bare `date` (no `/T`) prints the date AND asks for a new one — embarrassingly interactive for scripts. For combined output: `echo %DATE% %TIME%` (uses cmd built-in vars). `%DATE%` is locale-formatted (e.g. `Fri 05/16/2026`) — for ISO format, fall back to `wmic os get LocalDateTime` which returns a sortable `20260516120000.000000+xxx` string. Or just use pwsh: `powershell -NoProfile -Command "Get-Date -Format yyyy-MM-dd"`.

Worked examples

Print the current date in ISO format (YYYY-MM-DD)

Bash
date +%Y-%m-%d
Fish
date +%Y-%m-%d
PowerShell
Get-Date -Format "yyyy-MM-dd"
cmd.exe
wmic os get LocalDateTime ^| findstr /R "[0-9]"

Print the current date as ISO-8601 UTC (for log timestamps)

Bash
date -u +"%Y-%m-%dT%H:%M:%SZ"
Fish
date -u +"%Y-%m-%dT%H:%M:%SZ"
PowerShell
(Get-Date).ToUniversalTime().ToString("o")
cmd.exe
powershell -NoProfile -Command "(Get-Date).ToUniversalTime().ToString('o')"

Get the Unix epoch (seconds since 1970)

Bash
date +%s
Fish
date +%s
PowerShell
[DateTimeOffset]::Now.ToUnixTimeSeconds()

Gotchas

  • GNU `date` (Linux) and BSD `date` (macOS / FreeBSD) have INCOMPATIBLE arithmetic syntax. `date -d "yesterday"` works on Linux, errors on macOS. `date -v-1d` works on macOS, errors on Linux. For a script that runs on both, install `coreutils` via Homebrew (`brew install coreutils`) and call `gdate` — that gives you GNU `date` on macOS. Or shell out to pwsh on both: `pwsh -c "(Get-Date).AddDays(-1).ToString('yyyy-MM-dd')"`.
  • pwsh `Get-Date -Format "..."` uses .NET format strings, NOT strftime. `yyyy-MM-dd` (4-y, 2-M, 2-d — case-sensitive: lowercase `mm` is MINUTES, not month). `HH` is 24-hour, `hh` is 12-hour. The strftime conversion table: `%Y → yyyy`, `%m → MM`, `%d → dd`, `%H → HH`, `%M → mm`, `%S → ss`. The "o" round-trip format is closest to `%Y-%m-%dT%H:%M:%S.fffffffK`.
  • cmd `%DATE%` is LOCALE-DEPENDENT. On a US-English Windows it's `Fri 05/16/2026`; on a UK-English Windows it's `16/05/2026`; on a German Windows it's `Freitag, 16.05.2026`. Scripts that parse `%DATE%` break across locales. Use `wmic os get LocalDateTime` (always `YYYYMMDDHHMMSS.mmmmmm+ZZZ`) or pwsh `Get-Date -Format` (locale-independent format strings) for stable output.
  • Setting the system clock requires root / admin AND silently breaks scheduled jobs / TLS cert validation / Kerberos tickets if you jump backwards. For TIME ZONE changes (not actual clock): `timedatectl set-timezone Asia/Hong_Kong` (Linux systemd), `sudo systemsetup -settimezone Asia/Hong_Kong` (macOS), `tzutil /s "China Standard Time"` (Windows). Don't use `date -s` for "change the displayed time zone" — it changes the actual clock.
  • Daylight Saving Time is a date-arithmetic trap. `date -d "tomorrow 09:00"` (GNU) and `(Get-Date "tomorrow 09:00")` (pwsh) both handle DST correctly. RAW arithmetic like "add 86400 seconds" does NOT — across the spring-forward boundary, that's 25 actual wall-clock hours, not 24. For business logic ("same time tomorrow"), use the calendar APIs; for elapsed-time ("60 seconds from now"), use epoch math.

WSL & PowerShell Core notes

pwsh`Get-Date` works identically on Windows / Linux / macOS pwsh — returns a `[DateTime]` in local time. `[DateTime]::UtcNow` is the cross-platform UTC accessor. The TimeZone APIs differ slightly: `Get-TimeZone` returns the Windows-friendly name (`Pacific Standard Time`) on Windows pwsh, the IANA name (`America/Los_Angeles`) on Linux / macOS pwsh. For portable scripts that need IANA names, use `[TimeZoneInfo]::Local.Id` and post-process Windows IDs with a known mapping.
WSLWSL and the Windows host share the system clock (the WSL VM clock is slaved to the Windows host clock). Time-zone setting is per-side: WSL bash uses `TZ` env var / `/etc/localtime`, Windows uses the OS time-zone setting. The two can DIFFER intentionally — `date` in WSL might show 13:00 UTC while `time /T` in Windows shows 21:00 HKT. For "what timezone is WSL configured to": `cat /etc/timezone` or `readlink /etc/localtime`.

Common tasks using date

Related commands