How to Output Specific Dates with Bash date Command
This article introduces how to output yesterday’s date, tomorrow’s, several days ahead, and several days ago using the date command in Bash on Linux PCs and servers command line.
Output Yesterday’s Date
To output yesterday’s date, specify '-1 day' in the --date option.
$ date +%-m/%-d --date='-1 day'
Output Date Several Days Ago
For example, to output the date 7 days ago, specify '-7 day'.
$ date +%-m/%-d --date='-7 day'
Output example:
3/6
Output Date 1 Year Ago
To output the date 1 year ago, specify '-365 day'.
$ date +%-m/%-d --date='-365 day'
Output example:
3/13
Output Tomorrow’s Date
To output tomorrow’s date, specify '+1 day'.
$ date +%-m/%-d --date='+1 day'
Output Date Several Days Ahead
For example, to output the date 2 days ahead, specify '+2 day'.
$ date +%-m/%-d --date='+2 day'
Output example:
3/15
Output Date Several Days and Several Months Ahead
To output the date 2 days and 2 months ahead, specify '+2 day +2 month'.
$ date +%-m/%-d --date='+2 day +2 month'
Output example:
5/15
Reference Links
For more details, also refer to the related Stack Overflow thread.