I have an array ${timearray[*]} that contains a number of times in this format
20:56 20:57 20:59 21:01 21:04
There is a second array ${productarray[*]} that contains different times
20:54 20:56 20:58 21:00 21:02
I need to get a difference between the two by subtracting time minus product. To do this I believe I need to convert these times into epoch time before subtracting, I'll then divide by 60 and round to the nearest minute. I attempted using a for loop like this to do the conversion.
arraylength=`expr ${#timearray[@]} -1`
for ((l=0; l<=$arraylength; l++))
do
epochtimearray=(`date --date="${timearray[$l]}" +%s`)
done
However the resulting epochtimearray only contains the epoch value of the last time
echo ${epochtimearray[*]}
1472331840
Does anyone see what I'm missing here or is there a better way to subtract time times.