Apple - Shell Script for Yesterday's Date

Try using date like this:

dd=$(date -v -1d '+%m-%d-%y')

as mentioned yesterday is part of GNU Date, but using an offset of -1d should be equivalent for OS X use.


The date utility bundled with OS X is not GNU date (which accepts the --date option).

You can use homebrew to install it.

You can probably use Perl to get what you want:

perl -MPOSIX=strftime -le 'print strftime("%d-%m-%Y",localtime(time()-86400))'
# or
perl -MTime::Piece -MTime::Seconds -le 'print((Time::Piece->new - ONE_DAY)->dmy)'