Explore DATE command in your Operating System

In the Linux ecosystem, the date is used to print or display the current date and system time zone. With the help of the date command, we can print the date and time in a different format. The date commands provide the liberty to print the past and future dates also. The date command utility was written by David MacKenzie.

How does date command works?

The date command is able to print different type date format. By default, the date command will print the date as per the time zone which is configured in the UNIX or Linux operating system. We can also change the system time zone and print the different time zone date. For changing the time zone, you should have the root privileges. Generally, the date command will take the two set of arguments like option and date format. As per the inputs provided to it, it will manipulate the data and provide the date and time output in the request format.

Syntax used for date command

# date [option] [+format]

— You can even search for list of sequences in date command

# date --help

— The simple command to print date

# date 

— Use date command to display date for future/past.

# date -d last-week

— Use date command to tell a specific day

# date -d "2001-04-29" +"%A"

— Calculate the time for each epoch time.

this calculates time in seconds..

# date +%s

— Use date command to set time zone.

# TZ=PDT date

— Change system date in terminal.

# date --set="201901202 22:00"

List of Keyword's:

  • %a: It will display the weekday name example: Mon.
  • %A: It will display the full weekday name example: Monday.
  • %b: It will display the short month name example: Jan.
  • %B: It will display the long month name example: January.
  • %d: It will display the date of month example: 01.
  • %H: It will display the hour digit in 24hr format.
  • %I: It will display the hour digit in 12hr format.
  • %j: It will display the date of the year example: 001..366.
  • %m: It will display the month in digit format example: 01..12.
  • %M: It will display the minute value example: 00..59.
  • %S: It will display the second value example: 00..60.
  • %y: It will display the last two digit of year example: 20.
  • %Y: It will display the year example: 2020.

Full Documentation:https://www.gnu.org/software/coreutils/date

Windows DATE command:

— To know your current date.

# echo %date%

Windows commandline date command🔅



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store