How to find a date which is 7 days past when given current date

hii all.
I have to get the date of the 7th day past from the current date.
if i give the current date as sep 3 then i must get the date as 27th of august.
can we get the values from the "cal" command.
cal | awk '{print $2}' will this type of command work.
actually my need is
if today is wednesday then i want the files of the last wednesday.
please help me out...:confused:

fnsonlq0-/home/fnsonlq0>echo $TZ
IST-5:30
fnsonlq0-/home/fnsonlq0>date
Wed Sep 3 11:18:13 IST 2008
fnsonlq0-/home/fnsonlq0>TZ=IST+168
fnsonlq0-/home/fnsonlq0>date
Wed Aug 27 05:48:21 IST 2008

this might help you..

will this work for ksh

i didnt get the commands u gave
can u please be bit more clear

echo $TZ
whats the o/p you are getting??

The idea is to muck with the TZ (time zone) offset to get a date "transported" into a "time zone" which corresponds to the date and time offset you want to calculate.

Anyway, see the FAQ for more on this topic. http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html

hi
i am getting the output as
US/Arizona

i got the desired date but does it work for any date am giving..
eg for 3rd,4th etc.,

does it work for any time stamp.
my time is in MST.

try this:

date +%Y-%m-%d -d "7 day"

Output:

date
Wed Sep 3 09:39:02 IST 2008
TZ=IST-168
date ##get 7 days after date
Wed Sep 10 09:39:02 IST 2008
TZ=IST-5:30
date ##get old date

hi all...

itz working...
am able to get the date...
thanks so much':slight_smile:

If you are using ksh93, date arithmetic is built in i.e.

$ printf "%T\n" "7 days ago"
Wed Aug 27 20:27:12 EDT 2008
$ printf "%(%m-%d)T\n" "7 days ago"
08-27
$

Cool! :b: Never seen that before... move over GNU date!

but what the command u gave is not working.. :frowning:
my ksh is not supporting.
anyways i got a way out to find the date which is past 7 days
thanks

could you please mention it ladtony, how you can find 7days ago by using ksh programming

it's not working in ksh, as well ... try put 20090301 what is the result?
or 20090101 ?