Based on the usage report, I don't think you are on OS X. If you are on OS X, you can use the -v flag, but only with respect to the current date / time:
$ date +%Y%m%d 20130630 $ date -v-1d +%Y%m%d 20130629
If you have ksh , you can use it. I am not sure of the full syntax, so I donβt know if you can specify a base date, but you can do it relative to today:
$ ksh -c 'printf "%(%Y%m%d)T\n" yesterday' 20130629
Solaris (since version 10) still ships with the ridiculously old ksh88 by default ksh . You should find ksh93 (which supports the above syntax) in /usr/dt/bin/ksh :
$ /usr/dt/bin/ksh -c 'printf "%(%Y%m%d)T\n" yesterday' 20130629
If you have tclsh , you can use it:
$ echo 'puts [clock format [clock scan "yesterday"] -format %Y%m%d]' | tclsh 20130629 $ echo 'puts [clock format [clock scan "20130701 - 1 day"] -format %Y%m%d]' | tclsh 20130630
You already said that --date does not work, but for completeness: on systems using the GNU date version, you can use --date or -d :
$ date +%Y%m%d 20130630 $ date +%Y%m%d -d yesterday 20130629 $ date +%Y%m%d -d '-1 days' 20130629 $ date +%Y%m%d -d '20130701 - 1 day' 20130630
source share