Exploring Date Command in Linux

Rishabh Arya
3 min readSep 24, 2021

The date command in linux is used to display the current time in the given format, or set the system time.

Besides checking the date, you can do couple of more things using the date command like identifying a week or day from a date, calculating the time from epoch to a specified time, and a few more variations.

Some of its options are:

  1. -d , — date = “string” : Display the given date string.

2. Format options

  • date +”Year: %Y, Month: %m, Day: %d” : Here, the %Y character is replaced with the current year, %m with month, and %d with the day of the month:
  • date “+DATE: %D%nTIME: %T”
  • date +”Week number: %V Year: %y”

These are the most common formatting characters for the date command:

  • %D – Display date as mm/dd/yy
  • %Y – Year (e.g., 2020)
  • %m – Month (01-12)
  • %B – Long month name (e.g., November)
  • %b – Short month name (e.g., Nov)
  • %d – Day of month (e.g., 01)
  • %j – Day of year (001-366)
  • %u – Day of week (1-7)
  • %A – Full weekday name (e.g., Friday)
  • %a – Short weekday name (e.g., Fri)
  • %H – Hour (00-23)
  • %I – Hour (01-12)
  • %M – Minute (00-59)
  • %S – Second (00-60)

3. — set option : Set or Change Date in Linux.

4. Display the past and future dates : Use the --date option to display past and future dates in Linux.

5. -r : Print the last modification time of a file.

Thanks for reading 🙏

--

--

Rishabh Arya

I am an active learner who likes to challenge every problem with a can-do mindset in order to make any idea a reality.