Adding days to an input date.

Hello Unix gurus,

I need to add days to the input date and further use it in comparision with the existing date.
Im having issues sto add days to date,can you guys help me with script or function with which I can add days to the date.

Thanks,
Sud

date -d "+5 day" +"%D ?

Thanks for your reply hard_aix,it really works.
U ROCK !!!

I need to add days to a variable which stores the date.

Eg: If my variable date is 2/19/2009,I need to add 7 days so my output date should be 2/26/2009.

vdt2= $vdt2 + 7 (where $vdt2 is the variable date).

Im having errors when I try the same syntax with the input variable.

vdt2=/opt/freeware/bin/$vdt2 -d "+7 day" +"%D"

Any help?

Thanks,
Sud.

Look at the "--date" option of the date command. (info date). I think you can use that but I couldn't quickly figure out how to get it to take input in mm/dd/yy format.

date1='2009-02-19 00:00:00 +0000'
date2=$(/opt/freeware/bin/date --date="$date1" -d "+5 day" +"%D")
echo $date2 

Thanks for your input hard_aix but
date2=$(/opt/freeware/bin/date --date="$date1" -d "+5 day" +"%D") isnt working,I tried exploring the --date but Im still having issues converting string to the required date format.
Any light here will be greatly appreciated.

-Sud

??

Can you copy/paste and post what happens when you execute those 3 lines of code on your system?

Hard_AIX,
When I run those 3 lines I get the output as '2/25/09'.

But I want the date to be calculated from the variable date.

Eg:
When I run the below code I still get the output as '2/25/09' though my variable date is '02/01/09'

Date1='2009-02-01 00:00:00 +0000'
date2=$(/opt/freeware/bin/date --date="$Date1" -d "+5 day" +"%D")
echo $date2

It is ignoring the variable date.

Thanks,
Sud

Oh. Yes, you are right. It only works from the current date and I don't know if it can be made to work from another date.

In the past, on my system, I have used a shell script called shift_date. This is a slightly newer version than the one I have http://www.williamrobertson.net/code/shift_date.txt maybe you can get that to work.

here is a sample run from my system:

$ shift_date 20090101 -1
20081231

Thank you Sir but how do I use shift_date code..do I need to put it in some libraries? I created shift_date.ksh file by copying it from windows text file but ended up with ^M and I removed ^M using the following script.

cat -vet shift_date.ksh | sed -e s/\\^M\\$//g > temp_ftp_file.ksh
rm -f shift_date.ksh
mv temp_ftp_file.ksh shift_date.ksh

But I ended up with ^I instead of spaces.

Below is the extract from the file

^I^I^Ielif (( testyear % 400 == 0 ))
^I^I^Ithen
^I^I^I^Ileapyearanswer=${TRUE}
^I^I^Ifi
^I^Ielse
^I^I^Ileapyearanswer=${TRUE}
^I^Ifi
^Ifi

Please tell me how to remove that character.

Thanks.

Go to the url. On that page press ctrl-A (Select all) then crtl-c (copy).

On your aix system, open up your editor (vi?) make sure your are in insert mode and paste the copied text. Save it to a file called shift_date. Here I saved it into /usr/local/bin/shift_date but you can put in your home directory or /usr/bin/shift_date.

Then change persmissions on the file to make it executable;

chmod +x /pathto/shift_date

if the directory you are testing from is on your path you can just execute it directly as I did in the example above. Or put the path name on shift_date and execute it like this
/usr/local/bin/shift_date 20090101 -1