getting previous day.

Hi,
i am developing a script for my project. In my script i need to check some conditions based upon some values. in that one value is the previous date. with the previous date i need to check and process some values. I have a function with me retrieve the yesterdays date.

But now i have a scenario that i need to check with the yesteday day alone. That is say for example today is Thu,i need to check one day before that is with Wed. i am not sure how to retrieve this Thu-1.

I am trying `date %a -1` but its not working.

Please help me in this.

Thanks,
Raju

http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html

Try this,

date -d "1 day ago" | cut -d ' ' -f 1

You can try this,

date +%a -d "1 day ago"

This will give the yesterday day name in three letter format.For ex,Wednesday as Wed.If you want full day name,use %A instead of %a.

ksh93 include printf extension. Gnu date command include also epoc + calculation extensions. Some bsd date include -r option.
Ex. using ksh93

   printf "%T" now

More example to use printf and date calculation.

Or using gnu date command like

#!/someposixsh
epoc=$(date -u +%s)

echo $epoc
(( yesterday=epoc-86400 ))

datestr=$(date -d "1970-01-01  $epoc seconds"  )
echo  $datestr
datestr=$(date -d "1970-01-01  $epoc seconds" '+%Y-%m-%d %H:%M:%S' )
echo  $datestr
echo "yesterday:"
date -d "1970-01-01  $yesterday seconds" '+%Y-%m-%d %H:%M:%S'

If using date, read your man date.

The following example used for current date from ago

        #date
        Tue Feb 23 14:32:14 IST 2010

        #date -d "1 day ago"
        Mon Feb 22 14:32:18 IST 2010

        #date -d "1 week ago"
        Tue Feb 16 14:32:24 IST 2010

        #date -d "1 month ago"
        Sat Jan 23 14:32:29 IST 2010

         #date -d "1 year ago"
        Mon Feb 23 14:32:35 IST 2009
    The following example used for current date after
        #date
        Tue Feb 23 14:35:00 IST 2010

        #date -d "+1 day"
        Wed Feb 24 14:35:05 IST 2010

        #date -d "+1 week"
        Tue Mar  2 14:35:09 IST 2010

        #date -d "+1 month"
        Tue Mar 23 14:35:14 IST 2010

        #date -d "+1 year"
        Wed Feb 23 14:35:21 IST 2011

for more information read the date man page.

YESTERDAY=`TZ=CST+24 date +%Y%m%d`