DATE COMMAND
Introduction
Linux date command displays and sets the system date and time. This command also allows users to print the time in different formats and calculate future and past dates.
Prerequisites
Linux date Command Syntax
The syntax for the date command is:
date [option]... [+format]
How to Use date Command different way
To show the current system time and date, type in the date command:
Date Command Format Options
To format the date command’s output, you can use control characters preceded by a + sign. Format controls begin with the % symbol and are substituted by their current values
date +"Year: %Y, Month: %m, Day: %d"
Here, the %Y character is replaced with the current year, %m with month, and %d with the day of the month:
date "+DATE: %D%nTIME: %T"
date +"Week number: %V Year: %y"
These are the most common command for the date command:
Example
Display Past Date
Use the --date option to display past dates. The date command accepts values such as "tomorrow", "Friday", "last Friday", "next Friday", "next week", and similar.
date --date="3 year ago"
date --date="yesterday"
Display Future Dates
The --date option can also display future dates. Like with past dates, you can type in strings to print upcoming dates: