How to print the day before yesterday date in bash shell script

bash print day before yesterday

How to print the day before yesterday in bash?

Printing the day before yesterday date in the UNIX/Linux/Bash shell script is easy, here is the code:

date +%Y%m%d -d "2 days ago"

Here is a Demo, getting the date using a simple shell script.

[admin@codetryout ~]$ date
Thu Nov  7 02:30:08 EST 2019
[admin@codetryout ~]$ cat date.sh
#!/bin/bash
# printing day before yesterday date in unix shell script
DAY_BEFORE_YESTERDAY=$(date +%Y%m%d -d "2 days ago")
echo $DAY_BEFORE_YESTERDAY

[admin@codetryout ~]$ ./date.sh
20191105

Putting it in a shell script

The shell script for your reference:

#!/bin/bash
# printing day before yesterday date in unix shell script
DAY_BEFORE_YESTERDAY=$(date +%Y%m%d -d "2 days ago")
echo $DAY_BEFORE_YESTERDAY