date

What is date?

On Unix-like operating systems, the date command is used to print out, or change the value of, the system's time and date information.

How to use date

# syntax
date <options>

##### set date an time using -set option
date # output : Sun May 20 20:09:31 PDT 2013

date -s "Sun May 20 21:00:00 PDT 2013" # output : Sun May 20 21:00:00 PDT 2013

date # output : Sun May 20 21:00:05 PDT 2013

##### output from a string
date --date="12/2/2014" # output : Tue Dec  2 00:00:00 PST 2014
date --date="2 Feb 2014" # output : Sun Feb  2 00:00:00 PST 2014
date --date="Feb 2 2014" # output : Sun Feb  2 00:00:00 PST 2014

##### output from a string, with date and time
date --date="Feb 2 2014 13:12:10" # output : Sun Feb  2 13:12:10 PST 2014

##### read date patterns from a file using -file option
cat datefile
# output underneath
Sept 9 1986
Aug 23 1987

date --file=datefile
# output underneath
Tue Sep  9 00:00:00 PDT 1986
Sun Aug 23 00:00:00 PDT 1987

##### Display universal time using -u option
date # output : Mon May 20 22:07:53 PDT 2013
date -u # output : Tue May 21 05:07:55 UTC 2013 

Various date commands

# syntax
date + %<format-option>

##### examples 

date +%a # output : Mon
date +%F # output : 2020-09-14
date +%m # output : 09

Format options

Purpose of Option

Output

date +%a

Displays Weekday name in short (like Mon, Tue, Wed)

Thu

date +%A

Displays Weekday name in full short (like Monday, Tuesday)

Thursday

date +%b

Displays Month name in short (like Jan, Feb, Mar )

Feb

date +%B

Displays Month name in full short (like January, February)

February

date +%d

Displays Day of month (e.g., 01)

07

date +%D

Displays Current Date; shown in MM/DD/YY

02/07/13

date +%F

Displays Date; shown in YYYY-MM-DD

2013-02-07

date +%H

Displays hour in (00..23) format

23

date +%I

Displays hour (01..12) format

11

date +%j

Displays day of year (001..366)

038

date +%m

Displays month (01..12)

02

date +%M

Displays minute (00..59)

44

date +%S

Displays second (00..60)

17

date +%N

Displays nanoseconds (000000000..999999999)

573587606

date +%T

Displays time; shown as HH:MM:SS Note: Hours in 24 Format

23:44:17

date +%u

Displays day of week (1..7); 1 is Monday

4

date +%U

Displays week number of year, with Sunday as first day of week (00..53)

05

date +%Y

Displays full year i.e. YYYY

2020

date +%Z

alphabetic time zone abbreviation (e.g., EDT)

IS

Last updated

Was this helpful?