shell script to get yesterday’s date into a variable

a shell script which does the following to store the current day’s date in a variable ‘dt’:

date “+%a %d/%m/%Y” | read dt

echo ${dt}

How would i go about getting yesterdays date into a variable?

2 thoughts on “shell script to get yesterday’s date into a variable

  • February 1, 2014 at 7:09 am
    Permalink

    On Linux, you can use

    date -d “-1 days” +”%a %d/%m/%Y”

  • February 1, 2014 at 7:58 am
    Permalink

    bdate=`date -d “-31 days” +”%Y%m%d”`
    echo “$bdate”

Leave a Reply