Bash add the number of days to date OR get a specific future date

Here are a few examples to print specific future date in bash.

The date command and print options

In our examples, we have used a Year Month Date format for simplicity, you may choose other formats as per your requirements.

devops@codetryout:~$ date
Wednesday 29 September 2021 10:18:30 AM IST


devops@codetryout:~$ date +%Y%m%d
20210929

Let us explore some examples to print future dates in bash shell (or, print date after x days), we will be adding x number of days to the current system date.

Getting the current date, (or date and time)

devops@codetryout:~$ date
Wednesday 29 September 2021 10:18:30 AM IST

devops@codetryout:~$ date --date="today"
Wednesday 29 September 2021 10:18:55 AM IST

Printing tomorrow’s date

Here is an example to print tomorrow’s date in Linux

devops@codetryout:~$ date --date="tomorrow"
Thursday 30 September 2021 10:19:00 AM IST

Printing the date after 7 days

Another example in bash to print the date after 7 days

devops@codetryout:~$ date --date="7 days"
Wednesday 06 October 2021 10:19:23 AM IST

Printing the date after 30 days

Example to print date after 30 days

devops@codetryout:~$ date --date="30 days"
Friday 29 October 2021 10:19:30 AM IST

Printing the date after 90 days

Getting the date after 90 days from the current date

devops@codetryout:~$ date --date="90 days"
Tuesday 28 December 2021 10:19:38 AM IST

This can work across any OS or containers, such as Linux, Ubuntu, Docker, or Dockerfile, as long as you have a bash shell (/bin/bash).

In picture: