Skip to main content

Module 7: System Information & Monitoring

Lesson 68: date Command

In this lesson, you'll learn how to use the date command to display, set, and format system date and time in Linux.

The date command is an external bash program that allows you to set or display the system date and time.

It also provides several formatting options. It is installed in all Linux distros by default.

$ which date
$ type -a date
/usr/bin/date
date is /usr/bin/date

Type the date command in the terminal to display the current date and time.

$ date
Wed Nov 11 13:06:59 IST 2023

date Command Syntax

$ date [OPTIONS] [+FORMAT]

Date Format Specifiers

Specifier Description
%Y Full 4-digit year (e.g. 2023)
%y Last 2 digits of the year (e.g. 23)
%m Month as a number (01-12)
%b Abbreviated month name (e.g. Nov)
%B Full month name (e.g. November)
%d Day of the month (01-31)
%A Full weekday name (e.g. Wednesday)
%a Abbreviated weekday name (e.g. Wed)
%D Date in %m/%d/%y format
%F Date in %Y-%m-%d format
%H Hour in 24-hour format (00-23)
%M Minutes (00-59)
%S Seconds (00-60)
%N Nanoseconds
%s Unix epoch time (seconds since Jan 1, 1970)
%T Time in HH:MM:SS format (24-hour)
%r Time in 12-hour format

1. Change Linux System Date and Time

Using the date command, system date, time, and timezone can be modified. The change has to be synced with the hardware clock.

$ date --set="Thu Nov 12 13:06:59 IST 2020"
$ hwclock --systohc
Thu Nov 12 13:06:59 IST 2020

2. Formatting Options

A good place to get the full list of formatting options is the man page.

$ man date

Key points about formatting:

  • To apply formatting, use + followed by %formatter.
  • To get a list of formatting options for GNU/Linux, refer to the man page.
  • To get a list of formatting options for BSD, refer to the BSD man page.

The two important parts of the date command are using Format +% and the "--date" option.

To apply formatting, add the plus sign (+) followed by %formatter as shown in the examples below.

Pro TecMint Β· Root Plan
This Article is for Root Members
Join Root to read the full article and unlock everything

Full Access to Every Article, Course & Certification Track

Join thousands of Linux professionals who use Pro TecMint to advance their careers.

Ad-free access to all premium articles
All courses: Learn Linux, Bash, Golang, Ubuntu and more
RHCSA, RHCE, LFCS & LFCA certification prep
New courses added every month
Private Telegram community & priority support
Root Plan
$8/mo
or $59/year billed annually
Save $37 with annual plan
Start Reading This Article in the Next 60 Seconds
Join Root Plan β†’