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

Last updated