Many ways to use the date command on Linux

There’s a lot more to the date command than having it report the current date and time. You can change the command’s output format in many ways — report dates in the past and future, convert Unix and Linux timestamps into readable dates, display dates in UTC (Coordinated Universal Time), display dates in different time zones, rearrange the order of the date command output and do quite a bit more. Let’s take a look at some of the many options available to you.

Normal date/time display

The most common use of the date command is, of course, to simply type “date” and get the output in the default format like this:

$ date
Fri May 2 12:10:57 PM EDT 2025

To select the portions of the date output that you want to see, you can select what you want to see using some of the codes in the list below.

CodeMeaningExample output%YYear (4 digits)2025%mMonth (2 digits)04%dDay (2 digits)28%HHour (24-hour)16%IHour (12-hour)04%MMinute45%SSecond22%pAM or PMPM%AFull weekday nameMonday%BFull month nameApril

Here are some examples:

$ date +%A
Tuesday
$ date +%B
May
$ date +%H%p
11AM
$ echo Yesterday was `date --date="yesterday" +"%m-%d-%y"`
Yesterday was 05-01-25
$ echo Tomorrow will be `date --date="tomorrow" +"%m-%d-%y"`
Tomorrow will be 05-03-25

Showing future dates

The command below will display the date 10 days in the future:

$ echo Please have your report done by `date --date="+10 days"`
Please have your report done by Mon May 12 12:26:35 PM EDT 2025

Display the Unix timestamp (seconds since 1970-01-01 UTC):

$ date +%s
1746203311

You can also convert a timestamp back to a human-friendly date:

$ date -d @1746203311
Fri May 2 12:28:31 PM EDT 2025

The date -u commands displays the date and time in UTC (coordinated universal time):

$ date -u
Fri May 2 04:30:55 PM UTC 2025

You can display the date in ISO 8601 format like this:

$ date --iso-8601
2025-05-02

You can reach back and forward with the date command as in these examples:

$ date --date="next Friday"
Fri May 9 12:00:00 AM EDT 2025
$ date --date="3 months ago"
Sun Feb 2 11:36:28 AM EST 2025

In fact, you can be exceedingly detailed in your requests as shown in the example below.

$ date --date="2 years 4 months 1 week 3 days 7 hours 59 minutes ago"
Sun Sep 12 06:38:26 PM EDT 2027

The date command can provide a date-specific time stamp for file backups with a command like one of these:

$ cp myfile myfile_$(date +"%Y%m%d)
$ cp myfile myfile_$(date +"%Y%m%d_%H%M%S")

Verify your backups with a command like this and note the date/time details:

$ ls -l myfile*
-rw-r--r--. 1 shs shs 66 May 2 12:45 myfile
-rw-r--r--. 1 shs shs 66 May 2 12:49 myfile_20250502
-rw-r--r--. 1 shs shs 66 May 2 12:45 myfile_20250502_124524

Wrap-up

It’s nice to have a way to easily display the current date and time, but the date command on Linux can do far more than that – providing dates in the past and future and adjusting the date output to suit your need for details.

Source:: Network World