Exploring date command in Linux

Harshal Kondhalkar
3 min readSep 23, 2021

--

What is date command?

date is a command in Linux OS which displays the current date and time. By default the date command displays the date in the time zone on which Linux operating system is configured.

The date command can also be used in various different ways with its options as follows:

To see different options of date command use date — help command or man date command.

date -d “2020–10–17 10:05:26”

date — date=“10/05/2000”

date +“Year: %Y, Month: %m, Day: %d”

date “+DATE: %D%nTIME: %T”

date +“Week number: %V, Year: %y”

date +“mm/dd/yy: %D”

date +“Long month name: %B %nShort month name: %b”

date +“Date of month: %d %nDay of year: %j %nDay of week: %u”

date +“Full weekday name: %A %nShort weekday name: %a”

date +“24-Hour-Format: %H %M %S”

date — set=“20210920 10:14”

Past dates:

date — date=“4 year ago”

date — date=“yesterday”

date — date=“30 sec ago”

Future dates:

date — date=“next sunday”

date — date=“3 day”

date — date=“tomorrow”

cat>> datefile

Jul 3 1979

date — file=datefile

date -r /etc/hosts

TZ=‘America/New_York’ date

date -d ‘TZ=“Australia/Sydney” 06:07 next Sunday’

date +%s

date -d “2008–01–16” +%s

These were the few examples of date command with options.

Thank you!

--

--