Linux date Command
Generate date and time commands for GNU (Linux) and BSD (macOS). Pick a platform and operation — get a copy-ready shell command.
Select a platform and operation above
How to Use This Tool
Select GNU (Linux) or BSD (macOS) from the platform tabs, then choose an operation. The tool generates shell commands you can paste directly into your terminal or scripts. The date command syntax differs significantly between GNU and BSD — this tool shows the correct version for your platform.
If you're on macOS and want GNU syntax, install coreutils via Homebrew: brew install coreutils. This gives you gdate which accepts GNU flags.
Format Specifiers
These work identically on GNU and BSD. Use them after + in the format string.
| Specifier | Meaning | Example |
|---|---|---|
| %Y | 4-digit year | 2026 |
| %y | 2-digit year | 26 |
| %m | Month (01–12) | 03 |
| %B | Full month name | March |
| %b | Abbreviated month | Mar |
| %d | Day of month (01–31) | 26 |
| %e | Day of month (space-padded) | 5 |
| %j | Day of year (001–366) | 085 |
| %H | Hour, 24h (00–23) | 14 |
| %I | Hour, 12h (01–12) | 02 |
| %M | Minute (00–59) | 30 |
| %S | Second (00–60) | 45 |
| %N | Nanoseconds (GNU only) | 123456789 |
| %p | AM / PM | PM |
| %P | am / pm (lowercase, GNU only) | pm |
| %A | Full weekday name | Thursday |
| %a | Abbreviated weekday | Thu |
| %u | Day of week (1=Mon, 7=Sun) | 4 |
| %w | Day of week (0=Sun, 6=Sat) | 4 |
| %U | Week number (Sun start) | 12 |
| %V | ISO week number | 13 |
| %W | Week number (Mon start) | 12 |
| %s | Unix epoch (seconds) | 1774533600 |
| %Z | Timezone abbreviation | EDT |
| %z | Timezone offset | -0400 |
| %F | Shortcut: %Y-%m-%d | 2026-03-26 |
| %T | Shortcut: %H:%M:%S | 14:30:45 |
| %D | Shortcut: %m/%d/%y | 03/26/26 |
| %n | Newline | — |
| %t | Tab | — |
GNU vs BSD Syntax
| Operation | GNU (Linux) | BSD (macOS) |
|---|---|---|
| Yesterday | date -d 'yesterday' | date -v-1d |
| Tomorrow | date -d 'tomorrow' | date -v+1d |
| Add 3 days | date -d '+3 days' | date -v+3d |
| Subtract 2 months | date -d '-2 months' | date -v-2m |
| Add 1 year | date -d '+1 year' | date -v+1y |
| Parse date string | date -d '2026-03-26' | date -j -f '%Y-%m-%d' '2026-03-26' |
| Epoch to date | date -d @1774533600 | date -r 1774533600 |
| Date to epoch | date -d '2026-03-26' +%s | date -j -f '%Y-%m-%d' '2026-03-26' +%s |
| Nanoseconds | date +%N | Not available |
| Set system date | sudo date -s '2026-03-26' | sudo date 0326143026 |
Environment Variables
| Variable | Effect | Example |
|---|---|---|
| TZ | Override timezone for a single command | TZ=Asia/Tokyo date +%F_%T |
| LC_TIME | Change locale for date/time formatting | LC_TIME=fr_FR.UTF-8 date +%A |
| LC_ALL | Override all locale settings | LC_ALL=de_DE.UTF-8 date +%B |
Common Patterns & Recipes
Timestamped log files and backups
Loop through a range of dates
Measure script execution time
Frequently Asked Questions
How do I get the current date in bash?
date for the default format, date +%F for ISO date (2026-03-26), date +%T for time (14:30:45), or date '+%F %T' for both. These work on both GNU and BSD.
How do I get yesterday's date in bash?
GNU (Linux): date -d 'yesterday' +%F or date -d '-1 day' +%F. BSD (macOS): date -v-1d +%F. For N days ago, replace 1 with N.
What is the difference between GNU and BSD date?
GNU date uses -d for date strings and natural language (-d 'yesterday', -d '+3 days'). BSD date uses -v for offsets (-v-1d, -v+3d) and -j -f for parsing. Format specifiers (%Y, %m, etc.) are the same. Install GNU date on macOS with brew install coreutils (provides gdate).
How do I convert a Unix timestamp to a date?
GNU: date -d @1774533600 +%F (prefix with @). BSD: date -r 1774533600 +%F (use -r). Both default to local time. For UTC: prepend TZ=UTC.
How do I format a date for filenames?
date +%Y%m%d for compact date (20260326). date +%Y%m%d_%H%M%S for full timestamp. Use in scripts: backup_$(date +%Y%m%d).tar.gz. Avoid / and : in filenames — use underscores or hyphens.
How do I use a different timezone for one command?
Prefix with TZ=: TZ=Asia/Tokyo date +%F_%T. This affects only that command — your system timezone stays unchanged. Use IANA names like America/New_York, Europe/London, UTC.