How to Set Date Using Command-Line in Linux

Aashish Sunuwar Feb 02, 2024
  1. Use the date Command to Set Date in Linux
  2. Use the date Command to Set/Change the Date in Linux
How to Set Date Using Command-Line in Linux

Let’s see about using the date command in the Linux command line.

Use the date Command to Set Date in Linux

Let’s look at the date command, which can be used to view or change the system date and time.

Syntax:

date [option] [+format]

Use The date Command to Check the System Date in Linux

We can use the date command without any parameters to check the date.

date

Output:

Mon Jan 10 09:34:52 +0545 2022

The date command will print the date and time in day month date hour:minute: second time-zone year format. We use the date command followed by the format to check the date in a given format.

date "+%Y/%m/%d %H:%M:%S"

Output:

2022/01/10 09:33:53

Run date --help or the man date command to view all formatting choices.

Use the date Command to Set/Change the Date in Linux

We can use the -set or -s options to set the date. For this, we’ll need root permission.

sudo date -s "1997-10-21 10:10:10"

Use date to Display Past/Future Dates in Linux

We can also use the -date or -d options to see past or future dates.

date -d "last friday"
date -d "3 years ago"
date -d "next tuesday"

Output:

Fri 07 Jan 2022 12:00:00 AM UTC
Sat 12 Jan 2019 01:48:09 AM UTC
Tue 18 Jan 2022 12:00:00 AM UTC

Related Article - Linux Date