Calculate date difference

Hi All

Can you please help me with UNIX script code that will work with ksh shell on UNIX server

My Requirement

Time1: 09/17/13101536

Time2: 09/16/13101536

I want to calculate the difference in minutes for the dates with format given above. I have a requirement to wait for 30 mins from the start of the job before taking the next action and in the mean time also check for existance of a trigger file if the file is present than I dont need to wait for 30 mins infact take the action immediately.

Thanks

What's your system? Date math is easy on some systems and extremely difficult on others.

Its an IBM AIX system

---------- Post updated at 03:29 PM ---------- Previous update was at 03:25 PM ----------

Hi I am using the following code it works but the problem is that it does not take into account the date it works fine if its just time difference calculation on a same date

 timediff=`awk -v "time=$stTime" -v "date=$(date +%H:%M:%S)" '
  function abs(x) {return x<0 ? -x : x}
  BEGIN {
    split(time, ary, /[:,]/); t_sec = 3600*ary[1] + 60*ary[2] + ary[3]
    split(date, ary, /:/);    d_sec = 3600*ary[1] + 60*ary[2] + ary[3]
    # output difference in minutes
    print abs(t_sec - d_sec)/60
  }

Date math is much less trivial than time math, and about your only standard option for it on AIX is perl:

#!/usr/bin/perl

use Time::Local;

my @TA1=split(/\//, shift);
my @TA2=split(/\//, shift);

for($N=6; $N>=0; $N-=2)
{
        @TA1[2+($N/2)]=substr(@TA1[2], $N, 2);
        @TA2[2+($N/2)]=substr(@TA2[2], $N, 2);
}

@TA1[7]=timelocal(@TA1[5], @TA1[4], @TA1[3], @TA1[1], @TA1[0], @TA1[2]);
@TA2[7]=timelocal(@TA2[5], @TA2[4], @TA2[3], @TA2[1], @TA2[0], @TA2[2]);

print @TA1[7] - @TA2[7], "\n";
$ ./tdiff.pl 09/17/13101536 09/16/13101536
86400

$

Thank you so much for the reply but I am seeing that it does not give correct answer when I use 24 hrs time format like

./tdiff.pl 09/16/13231530 09/17/13001530 -3600

I was expecting to get 60 as the answer

Difference is in seconds, so -3600 is -60 mins