Display the last five dates from the given date

Hi all,

In Oracle we have got sysdate -1 to find the previous date. Is there any similar way to display date in unix shell scripting?

Kindly help me to display the last five dates from the given date

Thanks,
Geetha

Search datecalc in the forum

#!/bin/ksh93

for i in {1..5}
do
     printf "%(%D)T\n" "$i day ago"
done
07/09/09
07/08/09
07/07/09
07/06/09
07/05/09

Here's a little function I created. May not work on all linux systems. Thanks.

function days_ago {
  DAYAGO=$1
  set -- $(date -d "$DAYAGO days ago" "+%Y %m %d")
  YYYY=$1 ; MM=$2 ; DD=$3
  CHECKDATE=${YYYY}${MM}${DD}
  shift $#
}
DATE=$(date '+%s')  # now
for I in 0 1 2 3 4; do
  perl -e "print scalar(localtime($DATE)). \"\n\""
  let DATE=$DATE-86400 # 1 day ago
done
 
Fri Jul 10 17:56:11 2009
Thu Jul  9 17:56:11 2009
Wed Jul  8 17:56:11 2009
Tue Jul  7 17:56:11 2009
Mon Jul  6 17:56:11 2009

Hi
Please help on to display the dates if 1st of month is sunday,from sunday(Current month) to thursday of previous month.If its monday ,from monday to thursday of previous month

ex:
1st of month:01-03-2009(Sunday)
28-02-2009
27-02-2009
26-02-2009(thursday)

Thanks,
MR

with GNU date:

application GNUdate GNU date

you can use it to show the date as you expect:

for i in {1..5}
do
  gdate -d "$i days ago"
done

Hi
Thanks for your reply.Without GNU date ,How to to achive same thing?.
However I want to pass dynamically values

ex: IF 1st of month is sunday ,to dipaly upto thursdas(4 days)
IF 1st of month is monday ,to dipaly upto thursday(5 days)
IF 1st of month is saturday ,to dipaly upto thursdas(3 days)

$ cat list
for i in {0..6}
do
    THEDATE=`gdate -d "$1 $i days ago" +%Y%m%d`
    WEEKOFDATE=`gdate -d "$1 $i days ago" +%w `
    if [ ! $WEEKOFDATE = "4" ]; then
        echo $THEDATE
    else
        echo $THEDATE
        exit
    fi
done
$ ./list
20090921
20090920
20090919
20090918
20090917
$ ./list 01Aug2009
20090801
20090731
20090730
./list 01sep2009
20090901
20090831
20090830
20090829
20090828
20090827
$

Hi ,
Thanks for your reply .When trying with this script ,getting the below error ,It looks GNU is not enabled.Is there anyway to achive this.
a.sh[3]: gdate: not found.

Thanks,
MR

If you don't have GNU date, you need install it by yourself.

Which Linux/Unix do you use?

Using HP-UNIX