Name

date — stdin  stdout  - file  -- opt  --help  --version

Synopsis

date [options] [format]

The date command prints dates and times. The results will depend on your system’s locale settings (for your country and language). In this section we assume an English, US-based locale.

By default, date prints the system date and time in the local timezone:

$ date
Sun Sep 28 21:01:31 EDT 2003

You can format the output differently by supplying a format string beginning with a plus sign:

$ date '+%D'
09/28/03
$ date '+The time is %l:%M %p on a beautiful %A in %B'
The time is  9:01 PM on a beautiful Sunday in September

Here is a sampling of the date command’s many formats:

Format

Meaning

Example (US English)

Whole dates and times:

%c

Full date and time, 12-hour clock

Sun 28 Sep 2003, 09:01:25 PM EDT

%D

Numeric date, 2-digit year

09/28/03

%x

Numeric date, 4-digit year

09/28/2003

%T

Time, 24-hour clock

21:01:25

%X

Time, 12-hour clock

09:01:25 PM

Words:

%a

Day of week (abbreviated)

Sun

%A

Day of week (complete)

Sunday

%b

Month name (abbreviated)

Sep

%B

Month name (complete)

September

%Z

Time zone

EDT

%p

AM or PM

PM

Numbers:

%w

Day of week (0–6, 0=Sunday)

0

%u

Day of week (1–7, 1=Monday)

7

%d

Day of month, leading zero

02

%e

Day of month, leading blank

2

%j

Day of year, leading zeroes

005

%m

Month number, leading zero

09

%y

Year, 2 digits

03

%Y

Year, 4 digits

2003

%M

Minute, leading zero

09

Get Linux Pocket Guide, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.