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.

SpecifierMeaningExample
%Y4-digit year2026
%y2-digit year26
%mMonth (01–12)03
%BFull month nameMarch
%bAbbreviated monthMar
%dDay of month (01–31)26
%eDay of month (space-padded) 5
%jDay of year (001–366)085
%HHour, 24h (00–23)14
%IHour, 12h (01–12)02
%MMinute (00–59)30
%SSecond (00–60)45
%NNanoseconds (GNU only)123456789
%pAM / PMPM
%Pam / pm (lowercase, GNU only)pm
%AFull weekday nameThursday
%aAbbreviated weekdayThu
%uDay of week (1=Mon, 7=Sun)4
%wDay of week (0=Sun, 6=Sat)4
%UWeek number (Sun start)12
%VISO week number13
%WWeek number (Mon start)12
%sUnix epoch (seconds)1774533600
%ZTimezone abbreviationEDT
%zTimezone offset-0400
%FShortcut: %Y-%m-%d2026-03-26
%TShortcut: %H:%M:%S14:30:45
%DShortcut: %m/%d/%y03/26/26
%nNewline
%tTab

GNU vs BSD Syntax

OperationGNU (Linux)BSD (macOS)
Yesterdaydate -d 'yesterday'date -v-1d
Tomorrowdate -d 'tomorrow'date -v+1d
Add 3 daysdate -d '+3 days'date -v+3d
Subtract 2 monthsdate -d '-2 months'date -v-2m
Add 1 yeardate -d '+1 year'date -v+1y
Parse date stringdate -d '2026-03-26'date -j -f '%Y-%m-%d' '2026-03-26'
Epoch to datedate -d @1774533600date -r 1774533600
Date to epochdate -d '2026-03-26' +%sdate -j -f '%Y-%m-%d' '2026-03-26' +%s
Nanosecondsdate +%NNot available
Set system datesudo date -s '2026-03-26'sudo date 0326143026

Environment Variables

VariableEffectExample
TZOverride timezone for a single commandTZ=Asia/Tokyo date +%F_%T
LC_TIMEChange locale for date/time formattingLC_TIME=fr_FR.UTF-8 date +%A
LC_ALLOverride all locale settingsLC_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.

Related Tools