← Full reference

date

Current time in any format, date parsing and arithmetic (-d), Unix time and time zones (TZ=)

date prints the current time, and with -d any other date: it parses a string like 2025-01-15 10:00, yesterday or @1700000000, can add an interval and print the result in the format you need. This is GNU date from coreutils: on macOS and in BusyBox the options differ.

Syntax

date [options] [+FORMAT]

The format starts with + and consists of plain text and %x specifiers. If the format has spaces, quote it: date '+%F %T'.

Options

OptionWhat it does
-d 'string' / --date=show the given date instead of "now"
-utime in UTC (like TZ=UTC)
-I / -Iseconds / -InsISO 8601: 2025-01-05, 2025-01-05T14:07:09+00:00; also -Ihours, -Iminutes
-RRFC 5322 (for mail and HTTP): Sun, 05 Jan 2025 14:07:09 +0000
--rfc-3339=seconds2025-01-05 14:07:09+00:00; also date, ns
-r filethe file's last modification time
-f fileparse each line of the file as with -d
-s 'string'set the system time (needs privileges; in a container — Operation not permitted)
--debugshow how date understood the -d string

Format specifiers

SpecifierOutput (for 2025-01-05 14:07:09 UTC)
%Y / %y / %Cyear 2025 / 25 / century 20
%mmonth 01
%d / %eday of month 05 / 5 (space-padded)
%H / %khour 00–23 14 / space instead of zero
%I / %lhour 01–12 02 / 2
%p / %PPM / pm
%M / %Sminutes 07 / seconds 09
%Nnanoseconds 000000000; %3N — milliseconds
%sUnix time — seconds since 1970-01-01 UTC: 1736086029
%jday of year 005
%u / %wday of week: 1–7, Monday = 1 / 0–6, Sunday = 0
%a / %ASun / Sunday
%b / %BJan / January
%V / %GISO week number / ISO week year
%Uweek number, weeks starting on Sunday
%qquarter 1
%Z / %z / %:zzone UTC / +0000 / +00:00
%F%Y-%m-%d → 2025-01-05
%T%H:%M:%S → 14:07:09
%R%H:%M → 14:07
%D%m/%d/%y → 01/05/25 (US order)
%clocale date and time: Sun Jan 5 14:07:09 2025
%n / %t / %%newline / tab / a % sign

Modifiers between % and the letter: %-d — no leading zero (5), %_d — space instead of zero, %^a — upper case (SUN).

What -d understands

StringMeaning
2025-01-15, 2025-01-15 10:30, 2025-01-15T10:30:00a specific date and time
20250115, Jan 15 2025, 15 Jan 2025also work
01/02/2025January 2 (month/day/year)
@1700000000Unix time
now, today, yesterday, tomorrowrelative to the current moment
3 days ago, -7 days, 2 hours, 1 week, 1 monthoffset from the current moment
2025-01-15 3 days / 2025-01-15 -1 monthoffset from the given date
next monday, last fridaythe nearest next / previous weekday
2025-01-15 10:00 +0300time with an explicit zone offset
TZ="Asia/Tokyo" 2025-01-15 09:00a time given in another zone

Examples

# a date for a file name
date +%F                          # 2025-01-05
date +%Y%m%d-%H%M%S               # 20250105-140709

# a log line
date '+%F %T'

# Unix time now, and back to a date
date +%s
date -d @1700000000 '+%F %T'

# yesterday and a week ago
date -d yesterday +%F
date -d '7 days ago' +%F

# from a given date
date -d '2024-02-28 1 day' +%F    # 2024-02-29 — the leap year is accounted for

# difference between dates in days
echo $(( ($(date -d 2025-03-01 +%s) - $(date -d 2025-01-01 +%s)) / 86400 ))   # 59

# the same moment in different zones
TZ=Europe/Berlin date -d @1700000000 '+%F %T %Z'
TZ=America/New_York date -d @1700000000 '+%F %T %Z'

# convert a time from one zone to another
TZ=Europe/Berlin date -d 'TZ="Asia/Tokyo" 2025-01-15 09:00' '+%F %T'

# a file's modification time
date -r /etc/hostname '+%F %T'

# how date understood the string
date --debug -d 'next friday'

# day of the week for a list of dates from a file
date -f dates.txt +%A

Pitfalls

  • +N after a time is a time zone. date -d '2024-12-31 10:00 + 2 hours' gives 09:00: + 2 is read as the offset +02. Write it without the plus: '2024-12-31 10:00 2 hours'.
  • Months have different lengths. date -d '2025-01-31 1 month' gives 2025-03-03: February 31 "overflowed" into March. For "end of month", count from the first: date -d "$(date +%Y-%m-01) 1 month -1 day".
  • 01/02/2025 is US order, January 2. 31/12/2024 is an "invalid date" error. Use ISO: 2024-12-31.
  • A non-existent date is an error, not a rollover. date -d 2025-02-30 returns exit code 1.
  • TZ=UTC-3 means UTC+3. In POSIX notation the sign is reversed. Use names from /usr/share/zoneinfo: Europe/Berlin.
  • An unknown zone is not an error. TZ=Berlin date silently shows UTC labeled Berlin. Check that the file /usr/share/zoneinfo/<name> exists.
  • -u overrides TZ=. TZ=Europe/Berlin date -u … works in UTC.
  • The sandbox system zone is UTC (/etc/localtime → Etc/UTC); there are no localized month names, only English ones.
  • %N and almost all the options are GNU-specific. In a script for macOS or Alpine, date -d may not work.

See also

cron · variables · find