Yesterday

hi guys

i want to know how can i insert in a variable yesterday for example :

today=`date +%Y%m%d`

yesterday =???

thanks a lot

Hi.

Many choices:

Date, time arithmetic, math

        1) gnu date

        2) ksh ( version 93, not 88; ksh93 M 93t+ ) printf, e.g:
           printf "%(%Y-%m-%d)T\n" "yesterday"
           Many more examples ( as of 2017.07 ):
           http://blog.fpmurphy.com/2008/10/ksh93-date-manipulation.html

        3) date.pl (perl, limited arithmetic, but "date.pl -d '- 1 day'" works)
           ( http://www.unix.com/tips-tutorials/239167-general-purpose-date-script.html )

        4) dconv et al, e.g. ddiff, dconv, strptime (parsing), etc.
           ( dateutils: http://www.fresse.org/dateutils/ )

        5) tm2tm (c, OK in 32-bit; fails to compile in 64-bit)
           ( http://www.unix.com/shell-programming-scripting/146216-date-difference-between-freebsd-linux.html#post302463136 )

        6) perl custom formatting (with function POSIX::strftime, "perldoc POSIX")
           Generally, see http://search.cpan.org/search?query=date&mode=all

        7) date-cpan.pl, cpan perl date
           ( http://cpansearch.perl.org/src/CWEST/ppt-0.14/src/date/date.jgross )

        8) For small changes, say, "yesterday" in bash, ksh
           TZ=CST+24 date +%Y%m%d
           csh, tcsh
           setenv TZ CST+24 ; date +%Y%m%d

        9) Check for legal date:
           manstat:validata ( http://oldwww.acm.org/perlman/stat/ )

        10) Check for legal date:
            validate (local perl code)

        11) Shell, ksh, date calculations:
            www.unix.com/unix-for-dummies-questions-and-answers/4870-days-elapsed-between-2-dates.html

Best wishes ... cheers, drl

Depending on your date version (which you fail to mention), try

yesterday=$(date "+%Y%m%d" "-d-1day")

GNU date :

yesterday=`date --date="1 day ago" +%Y%m%d`

bash 4:

printf "%(%Y-%m-%d)T\n" $(( $(printf "%(%s)T\n") - 60*60*24 ))

Ugly, but it works.

Andrew