How can i get the yesterday's date in YYYYMMDD format

How can i get the yesterday's date in YYYYMMDD format???

echo "$(date +%y%m%d) - 1" | bc

is my suggestion, but is not working for the first of a month

I've found this thread

1 Like

Thanks funksen,
I got the solution.. i can use the following command

YESTERDAY=`TZ=aaa24 date +%Y%m%d`

and then echo the same

If you can install the gnu version of date it would be as simple as

date --date 'yesterday' +%Y%m%d

slight modification to funksen. it should be like below.

echo 2007`date +%m%d` - 1|bc