add 2hours in current time

hi
i want to add 2hr ( or any hours inputed by user) to current time
and print it.
can any one help me with script.

eg suppose current date is "10-sep-2008 23:10:00"
and if i added 4hrs to it output should be "11-sep-2008 03:10:00"

i want to run shell script in "ksh"

One way is to change the TZ variable in the script. example you are in MST (+7), pick a timezone two hours earlier like EST

export TZ=MST7MDT
date
export TZ=EST5EDT
date

the 7 and the 5 are important you can make up 3 letter names for the timezone, or just reuse the current timezone. You can fudge time by as much as +12 -12 hours.

Otherwise see the datecalc script in Perderabo's thread 'Date Arithmetic' in the forums FAQ.

please post the output of your echo $TZ
if you have date -d option you can do it with date also just go through the man page

the TZ solution is probably the simplest. In case you need something more arbitrary, perl comes in really handy, but this can also be done with a combination of date and bc.

perl -e 'print "" . localtime(time()+$ARGV[0]) . "\n";' 7200

Here, 7200 represents 2 hours of seconds. The code above gets the current time in seconds, adds to it the contents of the first argument, and translates it back into standard "date" format.

If the OP has GNU date. The whole thing sounds like homework to me.

hi
guys
thanks for your reply. !!

cant it done using only shell scripting. without using perl or doing changes to system like changing TZ

Probably. Please read the site rules.

Try the below one.

i was trying to do same thing. but i thing on my machine date -d option is not available.

date: illegal option -- d
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
getting this thing
i am using SunOS 5.7