Date Command In Linux With Example
Date Command In Linux

Date Command In Linux With Example

With the help of the date command in Linux, the user can display the date and time in the Linux system and set the date and time as per requirement. With this command, the user can print the time in a different format and can also calculate the past and future dates as per their requirement.

Linux date Command Syntax

There are many ways to display date and time in Linux system, even though you can check the current date and time of the system from GUI and you can also change it if needed, but in this article, we are discussing how to change and update the date from the terminal. If you want to print the date and time from the terminal then you have to use the below format

date [option]... [+format]

How to Check Date in Linux

date (no option) If you just run the date command in the Linux terminal it means you will not use any option with the date command then you will get the system abbreviated day name, abbreviated month name, date, and current system time separate buy colon, the timezone and year.

date
linux date command

-u Option If you add the –u option after the date command, you will print the system time and date in the GMT (Greenwich Mean Time)/UTC(Coordinated Universal Time) time zone.

date -u
check date in linux

Using –date option for displaying past dates: 

If you want to print the time and date of the previous month, year, day, and date, etc from the current date, then for this you have to use the –date or -d option after the date command and give the “string” which you want to print in the system Terminal.

#date --date=" string "
  • If you want to know which day was exactly 2 years ago from today, then for this you have to run the following command in the terminal,
$date --date="2 year ago"
check previous year date in linux
  • If you want to print the previous 30 second time from the current time, then for this you have to use the command given below
$date --date="30 sec ago"
check few second ago time
  • print the exact one date before time means yesterday time from the current system date and time then you have to use the below command.
#date --date="yesterday"
check previous day time
  • If you want to print the exact one-month before date and time from the current system time then you have to use the below command.
$date --date="1 month ago"
check one month ago date

Display Future Dates

You can print a future date using the date command and the –date option. In the previous section we used the –date option to check any previous date, in the same pattern, you can print any future date that you enter in the “string”.

  • If you want to know the date of next Saturday from the current date, then for that run the command given below.
#date --date="next monday"
check next day time
  • check the date and time after 8 days
check few date after time
  • To check the date and time of the next day from the current date.
To check the date and time of the next day from the current da
  • To check the date and time After Year from the current date.
check the date and time After Year from the current date

Set or Change Date in Linux

If you want to set or change the date and time of the Linux system, then you have to use the format given below. In the below screen you can look at what we have explained below screen 10(Month), 25(Date), 09(hours),55(Minutes), and 2025(Year). 56 (seconds) is set as the date and time. Similarly, you can set the date and time in Linux as per your requirement.

  • MM for Month
  • DD for Date
  • hh for Hours
  • mm for minutes
  • YY for year
#[MMDDhhmmYY][.ss]
#date 102509552025.56
change Linux date and time

Or

check Linux date and time

How to change the date using timedatectl

To change or update only the date of the system, use the format and command given below.

#timedatectl set-time YYYY-MM-DD
#timedatectl set-time '2024-12-25'
How to change the date using timedatectl

If you want to change both date and time with timedatectl command, then run the command given below.

Where,

  • HH: An hour.
  • MM: A minute.
  • SS: A second, all typed in two-digit form.
  • YYYY: A four-digit year.
  • MM: A two-digit month.
  • DD: A two-digit day of the month.

For example, to set the date ’26 Jan 2022′ and the time ’10:39:40 AM’ we ran the below command in the Linux system.

#timedatectl set-time YYYY-MM-DD HH:MM:SS
#timedatectl set-time '2022-01-26 10:39:40'
How to change the date and time  using timedatectl

How to Set System Time Only

if you want to change system time only then the run the below command.

#timedatectl set-time HH:MM:SS
# timedatectl set-time '15:25:13'
# date
How to Set System Time Only in linux

Change system time zone

If you want to change the timezone of a Linux system, then you must run the timedatectl command to check the system’s current time zone.

check Linux  system time zone

If you don’t know the time zone of your location in this case you can print all the time zone which is available in the Linux system. For this, you can run the below command

list all  system time zone

You can use the below command to change or set the timezone of the system.

Change system timezone in linux

Display The Hardware Clock (RTC) In Linux

If you want to check the hardware (BIOS) time of the system from the command line, for that you can use the hwclock command. In the below screen, you can check an example of hwclock command

# hwclock -r
Display The Hardware Clock (RTC) In Linux

Use the Help command for more information related date

If you want to get more information related to the Linux date command then you should read the manual page with the help command

#man date
Linux date help command

In this article, we have explained how to check and update date, time and time zone, etc from the command line in the Linux system. We hope after carefully reading this article will not have any doubts related to the date command in Linux. Comment for any type of feedback related to this article and Subscribe to our other blogs simiservice.com for information on tech products and reviews.

Related Article: what is help command in linux

Rate this post
simi kaithal