date — Print the current date and time, or format an arbitrary date across all 5 shells
Equivalents in every shell
dateExternal 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"`.
dateSame 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).
dateSame 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.
Get-DateReturns 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)`.
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)
date +%Y-%m-%ddate +%Y-%m-%dGet-Date -Format "yyyy-MM-dd"wmic os get LocalDateTime ^| findstr /R "[0-9]"Print the current date as ISO-8601 UTC (for log timestamps)
date -u +"%Y-%m-%dT%H:%M:%SZ"date -u +"%Y-%m-%dT%H:%M:%SZ"(Get-Date).ToUniversalTime().ToString("o")powershell -NoProfile -Command "(Get-Date).ToUniversalTime().ToString('o')"Get the Unix epoch (seconds since 1970)
date +%sdate +%s[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
Common tasks using date
- 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.
- Calculate days between two dates
Compute the integer number of days between two calendar dates — for SLA timers, log-window queries, license-expiry math, or backfill scripts that ask "how many days have passed since X?".
- Convert a timestamp between timezones
Take a date / time in one timezone and print its equivalent in another — for "what time is the 3pm Tokyo meeting in New York?", server-log normalization, and any cross-region scheduling task.
- Convert a Unix epoch to a human-readable date
Render a Unix-epoch integer (e.g. `1747396980`) as a readable date — for log inspection, file-metadata audits, and translating database timestamps.
- Format the current date as ISO 8601
Emit `YYYY-MM-DDTHH:MM:SS±HH:MM` (or the UTC `…Z` form) — the format every machine-readable log, JSON API, and database column should agree on.
- Get file modification time
Print the last-modification timestamp of a file — useful for cache invalidation, build-system checks, and freshness validation.
- Get the current time in UTC
Print the current wall-clock time in UTC (not local time) — essential for log correlation across machines and any DST-safe scheduling logic.
- Get the current timestamp
Print the current date / time as either a Unix epoch (seconds since 1970-01-01 UTC) or an ISO 8601 string — for log lines, filenames, expiry calculations, and HTTP `Date` headers.
- Get the day of the week for a date
Print which weekday a given date falls on — for backup-window scripts ("only run on Sunday"), log rotation, conditional CI gates ("skip the weekly job on Friday"), or `cron` replacements that need day-of-week introspection.
- Get the ISO week number of the year
Print which calendar week a date falls into — for sprint planning ("we are in W20"), retention dashboards (weekly bucketing), payroll periods, and any time-series workflow that wants "year-week" as a stable key.
- Parse a relative date like "next Friday" or "2 weeks ago"
Convert a human-readable relative-time expression ("3 days ago", "next Monday", "last quarter end") into an absolute date — for log filters, backfill ranges, scheduling, or any script that wants to accept user input the same way GitHub Actions cron does.
- Parse an ISO 8601 date string
Take a string like `2026-05-16T14:23:00Z` and convert it to a typed date object — for filtering logs by time, computing age, or feeding into date arithmetic.