Skip to content
shellmap

get-dateRead the current date or do date arithmetic in PowerShell across all 5 shells

Equivalents in every shell

Bashunix
date

GNU 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).

Zshunix
date

macOS 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.

Fishunix
date

Same 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.

PowerShellwindows
Get-Date

Returns 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`.

cmd.exewindows
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

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

Get the Unix epoch (seconds since 1970-01-01 UTC)

Bash
date +%s
PowerShell
[DateTimeOffset]::UtcNow.ToUnixTimeSeconds()
cmd.exe
powershell -NoProfile -c "[DateTimeOffset]::UtcNow.ToUnixTimeSeconds()"

Date 7 days ago, in ISO format

Bash
date -u -d "7 days ago" +"%Y-%m-%dT%H:%M:%SZ"
PowerShell
(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.

WSL & PowerShell Core notes

pwsh`Get-Date` is identical across Windows / Linux / macOS pwsh — same .NET DateTime model. The `-UFormat %s` UTC vs local-time bug is 5.1-only; pwsh 6+ ships fixed. For server scripts, prefer `[DateTimeOffset]::UtcNow` over `Get-Date` — explicit UTC eliminates timezone-cascade bugs.
WSLFrom WSL bash, `pwsh.exe -c "Get-Date"` returns Windows-side local time (uses Windows timezone settings); WSL `date` returns Linux-side local time. WSL2 inherits Windows timezone via systemd-timesyncd by default, but a stale `/etc/timezone` can desync — `sudo dpkg-reconfigure tzdata` to sync.

Related commands