get-date — Read the current date or do date arithmetic in PowerShell across all 5 shells
Equivalents in every shell
dateGNU date defaults to local time in the system's preferred format. Use `date -u` for UTC, `date +%s` for Unix epoch, `date +"%Y-%m-%d %H:%M:%S"` for ISO-like, `date -d "tomorrow"` for relative parsing (GNU only — BSD date uses `-v+1d` instead).
datemacOS ships BSD `date`. Date arithmetic uses `-v` flags: `date -v+1d` (one day from now), `date -v-1w` (one week ago), `date -v1d -v0H` (start of today). Different from GNU `date -d "..."` — porting Linux scripts to macOS often requires rewriting date-math expressions.
dateSame external `date` binary (GNU on Linux, BSD on macOS). Fish has no built-in date cmdlet — relies on the system tool. For cross-platform scripts, prefer ISO format strings via `date +"%Y-%m-%dT%H:%M:%S%z"` which both GNU and BSD format identically.
Get-DateReturns a `[DateTime]` object — not a string. `(Get-Date).AddDays(-7)`, `.AddHours(2)`, `.ToString("o")` for ISO 8601. `Get-Date -Format` uses .NET-style tokens (`yyyy-MM-dd HH:mm:ss`); `-UFormat` uses Unix-style tokens (`%Y-%m-%d %H:%M:%S`). Aliased as `gd`.
date /t`date` alone PROMPTS for input and lets you change the system date (admin only); `date /t` displays without prompting. Format is LOCALE-DEPENDENT (`MM/DD/YYYY` US vs `DD/MM/YYYY` UK vs `YYYY/MM/DD` JP) — scripting based on `%date%` breaks across regions. For portable cmd, shell out to PowerShell `powershell -c "Get-Date -Format yyyy-MM-dd"`.
Worked examples
Print the current date in ISO 8601 / RFC 3339 form
date -u +"%Y-%m-%dT%H:%M:%SZ"(Get-Date).ToUniversalTime().ToString("o")powershell -NoProfile -c "(Get-Date).ToUniversalTime().ToString('o')"Get the Unix epoch (seconds since 1970-01-01 UTC)
date +%s[DateTimeOffset]::UtcNow.ToUnixTimeSeconds()powershell -NoProfile -c "[DateTimeOffset]::UtcNow.ToUnixTimeSeconds()"Date 7 days ago, in ISO format
date -u -d "7 days ago" +"%Y-%m-%dT%H:%M:%SZ"(Get-Date).AddDays(-7).ToUniversalTime().ToString("o")Gotchas
- pwsh 5.1 `Get-Date -UFormat %s` returns the **LOCAL-TIME** epoch, not UTC — off by your timezone offset. **Always** use `[DateTimeOffset]::UtcNow.ToUnixTimeSeconds()` for portable epoch on 5.1. pwsh 7.2+ fixed `-UFormat %s` to return UTC, but the bug still exists on millions of 5.1 deployments.
- GNU `date -d "1 hour ago"` does NOT exist on macOS BSD `date` — you get `date: illegal option -- d`. macOS uses `date -v-1H` instead. For cross-platform scripts, do the arithmetic in a language that has consistent date APIs (Python, pwsh, node) rather than shell-date.
- `Get-Date -Format` (.NET-style) and `-UFormat` (Unix-style) accept DIFFERENT token sets. `yyyy-MM-dd` only works with `-Format`; `%Y-%m-%d` only with `-UFormat`. Mixing emits literally the wrong characters in the output without erroring. Pick one style per script.
- cmd.exe `%date%` and `%time%` are LOCALE-DEPENDENT — a script that parses `%date%` as `MM/DD/YYYY` breaks on a German user's machine where it's `DD.MM.YYYY`. For locale-independent date in cmd, use `wmic os get LocalDateTime /value` (ISO-like) or shell out to PowerShell.
- Timezone behaviour: `Get-Date` returns a `[DateTime]` with `Kind=Local` — when serialised to JSON, the timezone is DROPPED. For round-trip-safe timezone, use `[DateTimeOffset]::Now` (preserves UTC offset). When reading back, `[DateTime]::Parse("2026-05-16T10:00:00")` defaults to `Kind=Unspecified` — bugs cascade from there.