The date command in Linux: display and set the date and time

Introduction

The date command in Linux is an essential tool for displaying and setting the system date and time. Although it seems simple, its power lies in the multiple formatting options and its ability to work with time zones and Coordinated Universal Time (UTC). In this article we will explore from the most basic uses to advanced examples that will allow you to manage the time on your machine with precision.

Basic syntax of the date command

The simplest way to use date is to run it without arguments, which returns the current date and time according to the time zone configured on the system. Its general syntax is:

date [OPTIONS] [+FORMAT]

Where OPTIONS modify the behavior (such as showing universal time) and FORMAT is a string that specifies how the output should be presented.

Display the current date and time

Simply running:

date

produces output similar to:

Wed Sep 25 14:32:10 CEST 2025

This default format includes the day of the week, day of the month, month, hour, minutes, seconds, time zone, and year.

Custom output format

The true power of date is revealed when using the +FORMAT specifier. Each character preceded by a percent sign represents a component of the date or time. Some of the most used are:

  • %Y – four‑digit year (e.g. 2025)
  • %m – month as decimal number (01‑12)
  • %d – day of the month (01‑31)
  • %H – hour in 24‑hour format (00‑23)
  • %M – minute (00‑59)
  • %S – second (00‑59)
  • %a – abbreviated weekday name (e.g. Wed)
  • %A – full weekday name (e.g. Wednesday)
  • %b – abbreviated month name (e.g. Sep)
  • %B – full month name (e.g. September)

Common format examples

Combining these specifiers you can create formats adapted to different needs:

  • For an ISO‑8601 timestamp:
  • date '+%Y-%m-%dT%H:%M:%S%z'
  • For a legible presentation in Spanish:
  • date '+%A, %d de %B de %Y, %H:%M:%S'
  • For including only the date:
  • date '+%F'

Setting the system date and time

In addition to displaying, date allows adjusting the system clock. This operation requires root privileges, so it is usually executed with sudo. The syntax for setting a new date and time is:

sudo date MMDDhhmm[[CC]YY][.ss]

Where:

  • MM – month (01‑12)
  • DD – day of the month (01‑31)
  • hh – hour (00‑23)
  • mm – minute (00‑59)
  • CC – first two digits of the year (optional)
  • YY – last two digits of the year (optional)
  • .ss – seconds (optional)

For example, to set the clock to September 25, 2025 at 14:30:00 you would run:

sudo date 092514302025.00

This post is also available in ESPAÑOL.

Leave a Reply

Your email address will not be published. Required fields are marked *

Esta obra está bajo una Licencia Creative Commons Atribución 4.0 Internacional para Francesc Roig francesc@vivaldi.net .