Linux date Command
last modified October 23, 2026
The date command in Linux displays and sets the system date and
time. Beyond showing the current time, it formats timestamps, converts
between time zones and Unix time, parses date strings, and computes relative
dates such as tomorrow or two weeks ago.
date is commonly used in shell scripts for log messages,
time-stamped file names, and simple date arithmetic. The examples use GNU
date from coreutils with the en_US.UTF-8 locale and
the Europe/Bratislava time zone; the output of commands that
show the current time naturally depends on when they are run.
Current date and time
Without arguments, date prints the current date and time in the
default format of the locale.
date date -u
The -u option prints the time in Coordinated Universal Time
(UTC) instead of the local time zone.
$ date Fri 23 Oct 2026 10:39:13 AM CEST $ date -u Fri 23 Oct 2026 08:39:13 AM UTC
Custom formats
An argument starting with + is a format string. It contains
conversion specifiers introduced with %; other characters are
printed as they are.
date +"%Y-%m-%d %H:%M:%S" date +%F date +%T date +"%A, %B %d, %Y" date +"day %j of the year, week %V"
%Y, %m, and %d are the year, month,
and day; %H, %M, and %S are the
hours, minutes, and seconds. %F and %T are
shortcuts for %Y-%m-%d and %H:%M:%S.
%A and %B are the full weekday and month names,
%j is the day of the year, and %V is the ISO week
number. The quotes are needed when the format contains spaces.
$ date +"%Y-%m-%d %H:%M:%S" 2026-10-23 10:39:13 $ date +%F 2026-10-23 $ date +%T 10:39:13 $ date +"%A, %B %d, %Y" Friday, October 23, 2026 $ date +"day %j of the year, week %V" day 296 of the year, week 43
Standard formats
date has options for common standardized formats.
date -I date -Iseconds date -R date --rfc-3339=seconds
The -I option outputs ISO 8601; an optional precision such as
seconds adds the time and the UTC offset. The -R
option produces the RFC 5322 format used in email headers, and
--rfc-3339 outputs the RFC 3339 format.
$ date -I 2026-10-23 $ date -Iseconds 2026-10-23T10:39:13+02:00 $ date -R Fri, 23 Oct 2026 10:39:13 +0200 $ date --rfc-3339=seconds 2026-10-23 10:39:13+02:00
Unix timestamps
Unix time is the number of seconds elapsed since January 1, 1970 00:00:00 UTC.
date +%s date -d @1700000000 date -u -d @0
The %s specifier prints the current Unix timestamp. The
@ prefix in a -d argument converts a timestamp
back to a readable date; timestamp 0 is the start of the epoch.
$ date +%s 1792744753 $ date -d @1700000000 Tue 14 Nov 2023 11:13:20 PM CET $ date -u -d @0 Thu 01 Jan 1970 12:00:00 AM UTC
Parsing date strings
The -d option displays the time described by a string instead of
the current time. Combined with a format, it converts dates between formats.
date -d "2026-03-15 14:30" date -d "2026-03-15" +%A date -d "15 Mar 2026 2:30 PM" +"%F %R"
The second command finds the day of the week of a given date. The third one
parses a date written in a different style and prints it in ISO format;
%R is a shortcut for %H:%M.
$ date -d "2026-03-15 14:30" Sun 15 Mar 2026 02:30:00 PM CET $ date -d "2026-03-15" +%A Sunday $ date -d "15 Mar 2026 2:30 PM" +"%F %R" 2026-03-15 14:30
Relative dates
The -d option understands relative items such as
tomorrow, next Friday, +3 days, or
2 weeks ago.
date -d tomorrow +%F date -d "next Friday" +%F date -d "2026-01-31 +1 month" +%F date -d "2026-10-23 -2 weeks" +%F
The relative items can be applied to the current time or to an explicit date. Note how month arithmetic works: adding one month to January 31 gives February 31, which is normalized to March 3. To get reliable results, do month calculations from the middle of a month.
$ date -d tomorrow +%F 2026-10-24 $ date -d "next Friday" +%F 2026-10-30 $ date -d "2026-01-31 +1 month" +%F 2026-03-03 $ date -d "2026-10-23 -2 weeks" +%F 2026-10-09
Days between two dates
Converting dates to Unix timestamps makes it easy to compute differences.
start=$(date -u -d 2026-01-01 +%s) end=$(date -u -d 2026-12-25 +%s) echo $(( (end - start) / 86400 )) days
The difference in seconds is divided by 86400, the number of seconds in a
day. We use -u so that a daylight saving time change between
the two dates does not distort the result.
$ start=$(date -u -d 2026-01-01 +%s) $ end=$(date -u -d 2026-12-25 +%s) $ echo $(( (end - start) / 86400 )) days 358 days
Time zones
The TZ environment variable selects the time zone for a single
command. Time zone names come from the tz database, for example
America/New_York.
TZ="America/New_York" date TZ="Asia/Tokyo" date +"%F %T %Z" date -d "2026-10-23 09:00 UTC" +"%F %T %Z"
The first two commands show the current time in New York and Tokyo;
%Z prints the time zone abbreviation. The last command converts
a time given in UTC to the local time zone. The
timedatectl list-timezones command lists available zone names.
$ TZ="America/New_York" date Fri 23 Oct 2026 04:39:13 AM EDT $ TZ="Asia/Tokyo" date +"%F %T %Z" 2026-10-23 17:39:13 JST $ date -d "2026-10-23 09:00 UTC" +"%F %T %Z" 2026-10-23 11:00:00 CEST
File modification time
The -r option displays the last modification time of a file.
touch -d "2026-05-01 08:15" report.txt date -r report.txt
We set the modification time of report.txt with
touch -d and read it back with date -r. A format
string can be added as well, for example date -r report.txt +%F.
$ touch -d "2026-05-01 08:15" report.txt $ date -r report.txt Fri 01 May 2026 08:15:00 AM CEST
Dates in scripts
Command substitution inserts formatted dates into file names and log messages.
echo "backup-$(date +%Y%m%d-%H%M).tar.gz" echo "[$(date +"%F %T")] job started"
A file name built from the year, month, day, hour, and minute sorts chronologically, which is convenient for backups. The second command prints a log line with a timestamp.
$ echo "backup-$(date +%Y%m%d-%H%M).tar.gz" backup-20261023-1039.tar.gz $ echo "[$(date +"%F %T")] job started" [2026-10-23 10:39:13] job started
Measuring elapsed time
The %N specifier prints nanoseconds, which allows measuring
short durations.
start=$(date +%s.%N) sleep 1.2 end=$(date +%s.%N) echo "elapsed: $(echo "$end - $start" | bc) s"
We record the time before and after the sleep command and
compute the difference with bc, since Bash arithmetic supports
only integers.
$ start=$(date +%s.%N) $ sleep 1.2 $ end=$(date +%s.%N) $ echo "elapsed: $(echo "$end - $start" | bc) s" elapsed: 1.202975328 s
Setting the system time
The -s option sets the system clock; root privileges are
required.
sudo date -s "2026-10-23 12:34:56"
On systems with systemd, the clock is usually synchronized over the network
with NTP, and a manual change is overwritten soon. There, the time is managed
with timedatectl, for example timedatectl set-ntp false
followed by timedatectl set-time "2026-10-23 12:34:56". The
timedatectl set-timezone command changes the system time zone.
Best practices for date
- Use ISO 8601: Formats such as
%Fand-Iare unambiguous and sort correctly. - Prefer UTC for logs: Use
-uto avoid confusion around daylight saving time changes. - Quote format strings: Format strings with spaces must be quoted.
- Avoid manual clock changes: Rely on NTP and
timedatectlinstead ofdate -s.
Source
In this article, we have used the date command to display,
format, parse, and convert dates and times, compute relative dates, and work
with time zones and Unix timestamps.
Author
List all Linux tutorials.