write script for previous date

Hi all,
I need to write a unix shell script that will return the previous date of date entered and i have to consider leap year also.

For eg:- if i entered 2009-08-18 then the script should return 2009-08-17

can you please help me to write this script.???

Did you tried any code..?
then we can see what approach u r using..

#!/bin/ksh
timestamp=$(printf "%(%Y-%m-%d+%H:%M:%S)T" now) 
timeint=$(printf "%(%#)T" "$timestamp") 
((daysec=24*60*60)) 
((yesterday=timeint - daysec)) 

printf "yesterday %(%Y-%m-%d)T \n" "#$yesterday"

Thanks for your reply, but can you please explain me what you doing in this script.
My requirment is to pass the date as the parameter and script should return the previous date

add after 1st line, call script using date format yyyy-mm-dd

timestamp=$(printf "%(%Y-%m-%d+%H:%M:%S)T" now) 
[ "$1" != "" ] && timestamp=$(printf "%(%Y-%m-%d+%H:%M:%S)T" "$1+00:00:00") 

hi, thanks for your reply,i m trying to run this script on AIX box,but getting error...:(:frowning:

Need ksh93.
ksh Software Download Package List

Have you looked at "TZ" like in this post:
http://www.unix.com/unix-dummies-questions-answers/103390-need-pull-yesterdays-date.html

I knew I'd seen this someplace, as per the guidelines, remember to do a search of the forums first.
This should answer your question:
http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html

I hope its not a late reply mate, i have used such a good script as a part of back up script and it works fine, i hope its usefull for u:

#! /usr/bin/ksh

OFFSET=${1:-1}

case $OFFSET in
*[!0-9]* | ???* | 3? | 29) print -u2 "Invalid input" ; exit 1;;
esac

eval `date "+day=%d; month=%m; year=%Y`
typeset -Z2 day month
typeset -Z4 year
day=$((day - OFFSET))
if (( day <= 0 )) ;then
month=$((month - 1))
if (( month == 0 )) ;then
year=$((year - 1))
month=12
fi
set -A days `cal $month $year`
xday=${days[$(( ${#days[*]}-1 ))]}
day=$((xday + day))
fi

print $year$month$day

Regards

Try this

now=`date -d "15 Aug 2009" "+%s"
perl -e 'print scalar localtime('"$now"'-24*3600), "\n"'

Regards,

Ranjith

By setting timezone are GMT+24 can give you previous day

$ date
Thu Aug 20 13:59:27 BST 2009
$ TZ=GMT+24
$ date
Wed Aug 19 12:59:37 GMT 2009

setting TZ back to two days
$ TZ=GMT+48
$ date
Tue Aug 18 13:01:22 GMT 2009

Hi thanks for your reply.
I want to give an input as yyyy-mm-dd