date manipulation

I'm writing a ksh script in which I want to present the user with a choice of choosing any of the last 15 days. i.e., a list like the following:

20040510 (today)
20040509 (yesterday)
20040508
.
.
.
20040426

Is there an easy way to produce the date from x number of days ago other than converting today's date into Julian (day of the year) and then converting that into a month and day?

Thanks in advance!

Go to our home page.

Click on "Answers to Frequently Asked Questions".

Click on "Yesterdays Date/Date Arithmetic".

I wouldn't use the shell for date arithmetic, if you have perl installed...

#!/usr/bin/ksh
Days=15
PS3='Choose a date (or q to quit) ? : '
select Date in $(perl -e '
  $d = time();
  for ($i = 0; $i < $ARGV[0]; $i++) {
    @f = localtime($d);
    printf "%04d%02d%02d\n", $f[5]+1900, $f[4]+1, $f[3];
    $d-=86400;
  }' $Days)
do
  break
done
echo Date is ${Date?Aborted}

Thanks Perderabo & Ygor!!....it definitely looks easier to do with Perl instead of the shell. I don't use Perl very often...I didn't realize it had easy to use date functions. You have just saved me a few hours of headache.