before x days

hello,

I needed to put value of date - 20 days in certain variable like this:

before20d=`TZ=MET+480 date +%Y%m%d`

echo $before20d

value just perfect ...what I need and if I execute "date":

Wed Nov 10 11:58:43 MET 2010

on the other solaris platform if I execute this I get todays date..

if I execute "date":

Wed Nov 10 11:59:31 CET 2010

How to figure 20 days before on second platform...

thank you guys..

perl -e '($wday,$mon,$mday,$time,$year)=split(/\s+/,scalar gmtime(time - (20 * 86400)));print"$wday $mon $mday $time GMT $year\n";'

(20 * 86400) is your 20 days
you can use (20 * 24 * 3600) for hours per day

also you can use simple: perl -e 'print scalar gmtime(time - 20 * 86400),"\n";'
but there will be no GMT then

if you search the site you will find a number of similar queries.

Also there is an outstanding FAQ entry: http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html

You should find what you're looking for and more in there.

HTH

hmm..nice one..I modified it like this:

perl -e '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time - (20 * 86400));printf "%4d-%02d-%02d %02d:%02d:%02d\n",$year+1900,$mon+1,$mday,$hour,$min,$sec;'

perl is ok too..

thanks guys

xdays=20;echo "beforexdays -> $(perl -e 'use POSIX;print strftime "%Y-%m-%d\n",localtime time-24*60*60*'$xdays'')"