Hi.
A group of date-manipulation utilities is available, among them ddiff. Here's how it works with your sample data:
#!/usr/bin/env ksh
# @(#) s1 Demonstrate date arithmetic, differences, ddiff, dateutils.
# See:
# https://github.com/downloads/hroptatyr/dateutils/dateutils-0.2.3.tar.xz
# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C ksh ddiff
FILE=${1-data1}
pl " Input data file $FILE:"
cat $FILE
pl " Results, first-second, second-first:"
while :
do
if read v1 d1 t1 d2 t2 v2
then
x1=${d1}T${t1}
x2=${d2}T${t2}
db "first date-time of pair, x1 [$x1]"
db "last date-time of pair, x2 [$x2]"
else
break
fi
ddiff $x1 $x2 -f '%d days and %S seconds' -i "%m/%d/%YT%T"
ddiff $x2 $x1 -f '%d days and %S seconds' -i "%m/%d/%YT%T"
pe
done < $FILE
exit 0
producing:
$ ./s1
Environment: LC_ALL = POSIX, LANG = POSIX
(Versions displayed with local utility "version")
OS, ker|rel, machine: SunOS, 5.10, i86pc
Distribution : Solaris 10 10/08 s10x_u6wos_07b X86
bash GNU bash 3.00.16
ksh M-11/16/88i
ddiff 0.2.6
-----
Input data file data1:
name1 12/16/2013 10:56:38 12/16/2013 10:59:37 value1
name2 12/16/2013 04:37:41 12/17/2013 11:34:19 value2
-----
Results, first-second, second-first:
0 days and 179 seconds
0 days and -179 seconds
1 days and 24998 seconds
-1 days and -24998 seconds
This was run under ksh (some demo-support scripts use bash).
NAME
ddiff - Compute durations between dates and times
SYNOPSIS
ddiff [OPTION]... DATE/TIME [DATE/TIME]...
DESCRIPTION
ddiff 0.2.6
Compute duration from DATE/TIME (the reference date/time) to
the other DATE/TIMEs given and print the result as duration.
If the other DATE/TIMEs are omitted read them from stdin.
See the git web page noted in the script. One would need to download and compile the codes (written in c) as I have done today in Solaris:
-rwxr-xr-x 1 105904 Dec 22 12:35 ddiff
if this is beyond your skills then use other solutions above.
Best wishes ... cheers, drl