Difference between two timestamps Contd..

There was this thread earlier with the same name and the solution provided was excellent. Here is the solution to find diffrenc between two timestamp

$ cat timestamp
#! /usr/bin/ksh

echo enter first time stamp
read TIME1
echo enter second time stamp
read TIME2
H1=${TIME1%:+([0-9])}
M1=${TIME1#+([0-9]):}
H2=${TIME2%:+([0-9])}
M2=${TIME2#+([0-9]):}
H1=${H1#0}
M1=${M1#0}
H2=${H2#0}
M2=${M2#0}
((MAM1=H1*60+M1))
((MAM2=H2*60+M2))
((MAM1>MAM2)) && ((MAM2=MAM2+1440))
((diff=MAM2-MAM1))
echo diff = $diff 

my problem is, i have excecuted the same code in in AIX box and it works well, but while running this code in solaris i get the following error

$ ./Timestamp.sh
Start time: 00:13:01
End Time : 06:13:26
./Timestamp.sh: syntax error at line 18: `H1=${TIME1%:+' unexpected

Since the logic used here is excellent, but the problem is due to the Solaris,Any help will be much appreciated on how the H1=${TIME1%:+([0-9])} statement can be changed to run on solaris.
Thanks in advance :slight_smile:

HI,

H1=`echo ${a%:+([0-9])}`

just check with this code and let me know if that is working or not.

regards,
Sanjay

When i use the above code i get

$ ./Timestamp.sh
Start time: 00:13:01
End Time : 06:13:26
./Timestamp.sh: syntax error at line 1: `(' unexpected

So guess its not working..any other suggestions?

---------- Post updated at 03:50 PM ---------- Previous update was at 11:23 AM ----------

Hey Sanjay,

The command you proviided above works fine when run as a command but shows the error message when run through a script. i am slightly confused why it is acting so wierd in these two conditions. can anyone help??

are you getting the

"./Timestamp.sh: syntax error at line 1: `(' unexpected"

error or any thing else.

regards,
Sanjay

---------- Post updated at 11:48 AM ---------- Previous update was at 11:39 AM ----------

Just try with the following code

H1=`echo -e ${TIME1%:+([0-9])}`

Regards,
Sanjay