function timeDiff() { var=("" "") i=0 for str in $* do _year=${str:0:2} _month=${str:2:2} _day=${str:4:2} _time=${str:7} var[$i]="20"${_year}"-"${_month}"-"${_day}" "${_time} let i++ done strEnd=`date -d "${var[0]}" '+%s.%N'` strStart=`date -d "${var[1]}" '+%s.%N'` echo ${strEnd} ${strStart} | awk '{print $1-$2}' | more } timeDiff "$strEnd" "$strStart"