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
| Option | What it does |
|---|---|
-d 'string' / --date= | show the given date instead of "now" |
-u | time in UTC (like TZ=UTC) |
-I / -Iseconds / -Ins | ISO 8601: 2025-01-05, 2025-01-05T14:07:09+00:00; also -Ihours, -Iminutes |
-R | RFC 5322 (for mail and HTTP): Sun, 05 Jan 2025 14:07:09 +0000 |
--rfc-3339=seconds | 2025-01-05 14:07:09+00:00; also date, ns |
-r file | the file's last modification time |
-f file | parse each line of the file as with -d |
-s 'string' | set the system time (needs privileges; in a container — Operation not permitted) |
--debug | show how date understood the -d string |
Format specifiers
| Specifier | Output (for 2025-01-05 14:07:09 UTC) |
|---|---|
%Y / %y / %C | year 2025 / 25 / century 20 |
%m | month 01 |
%d / %e | day of month 05 / 5 (space-padded) |
%H / %k | hour 00–23 14 / space instead of zero |
%I / %l | hour 01–12 02 / 2 |
%p / %P | PM / pm |
%M / %S | minutes 07 / seconds 09 |
%N | nanoseconds 000000000; %3N — milliseconds |
%s | Unix time — seconds since 1970-01-01 UTC: 1736086029 |
%j | day of year 005 |
%u / %w | day of week: 1–7, Monday = 1 / 0–6, Sunday = 0 |
%a / %A | Sun / Sunday |
%b / %B | Jan / January |
%V / %G | ISO week number / ISO week year |
%U | week number, weeks starting on Sunday |
%q | quarter 1 |
%Z / %z / %:z | zone 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) |
%c | locale 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
| String | Meaning |
|---|---|
2025-01-15, 2025-01-15 10:30, 2025-01-15T10:30:00 | a specific date and time |
20250115, Jan 15 2025, 15 Jan 2025 | also work |
01/02/2025 | January 2 (month/day/year) |
@1700000000 | Unix time |
now, today, yesterday, tomorrow | relative to the current moment |
3 days ago, -7 days, 2 hours, 1 week, 1 month | offset from the current moment |
2025-01-15 3 days / 2025-01-15 -1 month | offset from the given date |
next monday, last friday | the nearest next / previous weekday |
2025-01-15 10:00 +0300 | time with an explicit zone offset |
TZ="Asia/Tokyo" 2025-01-15 09:00 | a 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
+Nafter a time is a time zone.date -d '2024-12-31 10:00 + 2 hours'gives09:00:+ 2is 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'gives2025-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/2025is US order, January 2.31/12/2024is an "invalid date" error. Use ISO:2024-12-31.- A non-existent date is an error, not a rollover.
date -d 2025-02-30returns exit code 1. TZ=UTC-3means 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 datesilently shows UTC labeledBerlin. Check that the file/usr/share/zoneinfo/<name>exists. -uoverridesTZ=.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. %Nand almost all the options are GNU-specific. In a script for macOS or Alpine,date -dmay not work.