date is two commands sharing a name. One prints a moment — now, by default — in any format you can describe, which is how every log file name, backup directory and report header gets its timestamp. The other takes a description of a moment in something close to English (“next monday”, “2 days ago”, “2026-03-01 09:00 Europe/London”, a file’s modification time, a number of seconds since 1970) and turns it into a date you can print, compare or do arithmetic with. The first is simple and the second is why this page exists: GNU date‘s parser is generous, undocumented in the places people look, and wrong in one specific way that bites scripts silently.
date '+%Y-%m-%d %H:%M:%S %z'
date -u +%Y%m%dT%H%M%SZ
date -d '2 days ago' +%FA + argument is an output format; -d (or --date=) is an input to parse instead of “now”; -u prints in UTC; -r FILE uses the file’s modification time; -s sets the system clock, and is covered at the end because it deserves a warning. Measured on coreutils 9.4, the version in current Ubuntu and Debian; the behaviour described here has been stable for many years.
$ date
Sun Nov 29 20:24:51 UTC 2026
$ date '+%Y-%m-%d %H:%M:%S %z'
2026-11-29 20:24:51 +0000
$ date -u +%Y%m%dT%H%M%SZ
20261129T202451Z
$ date +%s
1795983891
$ date --iso-8601=seconds
2026-11-29T20:24:51+00:00
$ date --rfc-3339=seconds
2026-11-29 20:24:51+00:00
$ date --rfc-email
Sun, 29 Nov 2026 20:24:51 +0000The plus sign that becomes a time zone
Immediately after a time of day, a signed number is a UTC offset, not a quantity. 12:00 + 3 hours is parsed as twelve o’clock in the zone UTC+3, followed by the word hours on its own, which means one hour. The result is ten o’clock, not three in the afternoon, and date says nothing. Measured:
$ date -d '2026-11-29 12:00 + 3 hours'
Sun Nov 29 10:00:00 UTC 2026
$ date -d '2026-11-29 12:00 3 hours'
Sun Nov 29 15:00:00 UTC 2026
$ date --debug -d '2026-11-29 12:00 + 3 hours' 2>&1 | head -3
date: parsed date part: (Y-M-D) 2026-11-29
date: parsed time part: 12:00:00 UTC+03
date: parsed relative part: +1 hour(s)The idiom date -d "$(date '+%F %T') + 1 hour", which appears in a great many scripts, has exactly this problem; it produces a time one hour in the past at UTC+1, which happens to be the right answer in one time zone and wrong everywhere else. now + 3 hours and today + 3 hours are safe, because now is not a time of day. So is naming the zone, which fills the slot the sign would otherwise take: 12:00 UTC + 3 hours gives 15:00. The reliable habits are to drop the sign (12:00 3 hours, 12:00 3 hours ago), and to run anything non-trivial through --debug once, which prints what each word was taken to mean.
Output formats
| Sequence | Prints |
|---|---|
%F | 2026-11-29 — the same as %Y-%m-%d, and the only date format that sorts correctly as text |
%T | 20:24:51 — the same as %H:%M:%S |
%s | Seconds since 1970-01-01 00:00 UTC; %s%N for nanoseconds appended, %s.%3N for milliseconds |
%z / %:z / %Z | Offset +0000 / +00:00 / abbreviation UTC, GMT, BST — the abbreviation is ambiguous (three zones use CST); log the offset |
%A %a %B %b | Weekday and month names, full and short, in the current locale |
%u / %w | Weekday as a number: Monday 1 to Sunday 7 / Sunday 0 to Saturday 6 |
%j | Day of year, 001–366 |
%V %G | ISO week number and the year it belongs to — %U and %W count differently (weeks starting Sunday or Monday, from week 00) and are almost never what is wanted |
%-d %-m %-H | A - after the percent strips the leading zero; %e pads the day with a space |
--iso-8601=seconds | 2026-11-29T20:24:51+00:00; =date, =minutes, =ns set the precision |
--rfc-3339=seconds | The same with a space instead of T |
--rfc-email | The Date: header format |
For anything a machine will read later — file names, log lines, JSON — use -u with %Y%m%dT%H%M%SZ or --iso-8601=seconds, or plain %s. Both sort as text, both carry the zone, and neither depends on the locale. Sun Nov 29 is for humans, and %A %B change language with LC_ALL, so a script that greps for “Nov” will one day run under a locale that says “nov.” or “Nov” in another alphabet. The one week-number format worth using is %V, and only together with %G: on this machine 2026-01-01 is ISO week 01 of 2026 but %U week 00, and 2026-12-31 is ISO week 53.
Parsing: what -d understands
date -d tomorrow # same time of day tomorrow
date -d 'tomorrow 03:00' # a time of day resets the clock part
date -d yesterday +%F # a date only: 2026-11-28
date -d '2 days ago' +%F # 2026-11-27
date -d 'next monday' +'%F %a' # 2026-11-30 Mon
date -d 'last friday' +'%F %a' # 2026-11-27 Fri
date -d friday +'%F %a' # 2026-12-04 Fri — the coming one, or today if today is one
date -d '2026-11-29 90 days' +%F # 2027-02-27
date -d '90 days ago' +%F # relative to now
date -d @1700000000 -u # Tue Nov 14 22:13:20 UTC 2023
date -r /var/log/syslog # a file's mtime
date -d 'Sun, 29 Nov 2026 20:25:16 GMT' +%s # an HTTP Date header to epochRelative words combine with absolute ones: a date, an optional time, a zone, then relative items. tomorrow keeps the current time of day unless a time is given, so a cron-style “tomorrow at three” is tomorrow 03:00. A bare weekday name means today if today is that day and otherwise the coming one (this friday is the same thing); next friday is the first Friday strictly after today, so on a Friday it is a week away, and last friday on a Friday is a week back. Measured on a Sunday: sunday gave today, next sunday gave seven days on, 2 sunday fourteen. @N is seconds since the epoch, and it is the only way to pass one in: date -d 1700000000 is an error, and so is @1700000000 + 3 hours, because nothing may follow an epoch value. -r reads a file’s timestamp, and stat -c %Y fed back through -d @ is the general version of it.
$ date -d '03/04/2026' +%F
2026-03-04
$ date -d '03.04.2026' +%F
date: invalid date '03.04.2026'
$ date -d '20261129T2025'
Mon Nov 30 03:25:00 UTC 2026
$ date --debug -d '20261129T2025' 2>&1 | sed -n 2p
date: parsed zone part: UTC-07Absolute dates are where the generosity hurts. Slashes are read American, month first, always, whatever the locale: 03/04/2026 is the fourth of March. Dots are rejected outright. ISO forms (2026-04-03, 2026-04-03T20:25:16+01:00, 2026-04-03 20:25 UTC) are read correctly, and so are the spelled-out forms (3 Apr 2026, Apr 3 2026). The compact 20261129T2025 is not: the T is taken as the military time-zone letter for UTC−7, and the result is seven hours off with no complaint. Feed -d ISO dates with separators and the zone written out, and nothing else, and when a log line’s format is anything else, convert it first.
Time zones, in and out
$ TZ=America/New_York date -d '2026-11-29 20:30 UTC'
Sun Nov 29 15:30:00 EST 2026
$ date -u -d 'TZ="America/New_York" 2026-11-30 09:00'
Mon Nov 30 14:00:00 UTC 2026
$ TZ=UTC date -d 'TZ="Asia/Tokyo" 2026-11-30 09:00'
Mon Nov 30 00:00:00 UTC 2026Two zones are in play in any conversion: the zone the input is written in and the zone the output is printed in. The TZ environment variable sets the output zone (and the default input zone); TZ="…" inside the -d string, quotes included, sets the input zone alone. So “what is 9 a.m. New York in UTC” is the second line, and “what is this UTC timestamp in New York” is the first. Zone names are the IANA ones under /usr/share/zoneinfo; abbreviations like EST and IST are accepted on input but are ambiguous, and date resolves them silently to one meaning. timedatectl is where the machine’s own zone is set, and How Time Works on a Linux Machine is the page on why the kernel keeps UTC and everything else is presentation.
Arithmetic that is not what it looks like
$ date -d '2026-01-31 1 month' +%F
2026-03-03
$ date -d '2026-03-31 1 month ago' +%F
2026-03-03
$ date -d 'last day of month'
date: invalid date 'last day of month'
$ date -d "$(date +%Y-%m-01) 1 month 1 day ago" +%F # last day of this month
2026-11-30
$ date -d "$(date +%Y-%m-01) 1 day ago" +%F # last day of last month
2026-10-31“One month” adds one to the month number and lets the calendar normalise the result, so 31 January plus a month is “31 February”, which is 3 March; and 31 March minus a month is 3 March as well, not the end of February. A monthly job scheduled by this arithmetic drifts and double-fires. Anchor to the first of the month, as the last two lines do, and derive the end of a month by going forward one month and back one day. Years behave the same way on 29 February. There is no last day of month keyword, however natural it reads.
$ TZ=Europe/London date -d '2026-03-29 01:30'
date: invalid date '2026-03-29 01:30'
$ TZ=Europe/London date -d '2026-03-28 12:00 1 day'
Sun Mar 29 12:00:00 BST 2026
$ TZ=Europe/London date -d '2026-03-28 12:00 24 hours'
Sun Mar 29 13:00:00 BST 2026Daylight-saving transitions add the second class of surprise. A time inside the spring gap does not exist in that zone and date rejects it, which is correct but will fail a script on exactly one night a year. And 1 day is not 24 hours: a day keeps the wall-clock time across the change, hours do not, and either can be the one you meant. Timers that must fire at a wall-clock time want days; durations and expiries want hours, or better, %s arithmetic, which has no zones at all:
now=$(date +%s)
deadline=$(date -d '2027-01-01' +%s)
echo $(( (deadline - now) / 86400 )) days # 32 days, measured
echo $(( $(date -d 'tomorrow 00:00' +%s) - now )) seconds to midnight
age=$(( now - $(stat -c %Y /var/backups/latest) )) # seconds since a file changed
[ "$age" -gt 90000 ] && echo "backup is more than a day old"Empty strings and -s
$ date -d ''
Sun Nov 29 00:00:00 UTC 2026
$ echo $?
0An empty string is a valid date: midnight today, exit status zero. A script that builds -d "$since" from a variable that turned out unset does not fail; it quietly reports on everything since midnight, and a report, a cleanup or a billing run built on it is wrong without saying so. Test the variable before date sees it. The same rule makes date -s '' set the system clock to midnight, which is how this fact was discovered while writing this page, on a sandbox machine, with the clock restored from a server’s HTTP Date header a minute later. Do not use date -s on a machine you care about. It steps the clock, which breaks running timers, log ordering, TLS checks and database replication for the width of the step; timedatectl set-time at least goes through systemd, and a machine with NTP configured should not have its clock set by hand at all. How Time Works has the list of what a stepped clock does not write down.
Common problems
| Symptom | Cause | Check / fix |
|---|---|---|
-d '… 12:00 + 1 hour' gives a time in the past | The +1 after a time is a UTC offset | Drop the sign, name the zone, or use now + 1 hour; --debug |
| A date in a file name is in the wrong month | Slashes read as MM/DD | ISO input only |
| Compact timestamp off by hours | T read as a military zone letter | Separators: 2026-11-29T20:25 is fine |
| Monthly job runs twice or skips | 1 month on the 29th–31st normalises into the next month | Anchor to day 1 and go forward then back |
| Script fails once a year | Nonexistent local time during the DST gap | Compute in UTC or epoch; convert for display |
| Report “since” covers today instead of the intended range | Empty variable, parsed as midnight | : "${since:?unset}" before calling date |
grep Nov on date output stops matching | Locale changed the month name | %F/%m, or LC_ALL=C |
| Week numbers disagree with the calendar on the wall | %U/%W instead of ISO | %V with %G |
date -d 1700000000 is an error | Epoch needs the @ | -d @1700000000; nothing may follow it |
| Logs from two machines an hour apart | One prints local time without an offset | Always include %z, or log in UTC |
Quick reference
date -u +%Y%m%dT%H%M%SZ # file-name safe, sortable, UTC
date --iso-8601=seconds # 2026-11-29T20:24:51+00:00
date +%s # epoch seconds
date -d @1700000000 # epoch to date
date -d 'yesterday' +%F # a date, relative
date -d 'next monday 06:00' # a moment, relative
date -d '2026-11-29 12:00 3 hours' # NO plus sign after a time
date -d 'now + 3 hours' # a plus is safe after "now"
date -d "$(date +%Y-%m-01) 1 month 1 day ago" +%F # end of this month
TZ=Asia/Tokyo date # now, shown in another zone
date -u -d 'TZ="Asia/Tokyo" 09:00' # a Tokyo time, shown in UTC
date -r file # a file's mtime
date --debug -d '...' # what each word was taken to mean
: "${when:?}"; date -d "$when" # never pass an empty stringRelated reading
- How Time Works on a Linux Machine — the clock underneath, why it is UTC, and what a step does to everything running
- timedatectl — setting the zone and the clock the supported way, and why logs end up an hour out
- cron — where most
datearithmetic ends up, and the month-end jobs that drift - systemd Timers —
OnCalendarhas its own calendar expressions, with a built-in last-day-of-month (~01) - The Life of a Scheduled Job — the DST night, the empty variable and the other ways a job runs and produces the wrong thing
- stat —
%Y,%Zand the other epoch fields thatdate -d @turns back into dates

