It seems impossible to use mktime to extract elapsed time from two date time stamps

mktime() requires a text string with month specified as an integer value but unix date command gives it an abbreviated month. This is odd given mktime is intended for comparing times. Particularly for calculating elapsed time between two dates.

month()

Gawk code convert abbreviated month name text (e.g. "May") into number suitable for %m in mktime() (e.g. 5).
#http://het.as.utexas.edu/HET/Projects/WindRose/selecttimes.awk
function month(text,  mon) {
  #
  # Convert a month name to a month number
  #

  if (text ~ /Jan/ ) mon = 1
  if (text ~ /Feb/ ) mon = 2
  if (text ~ /Mar/ ) mon = 3
  if (text ~ /Apr/ ) mon = 4
  if (text ~ /May/ ) mon = 5
  if (text ~ /Jun/ ) mon = 6
  if (text ~ /Jul/ ) mon = 7
  if (text ~ /Aug/ ) mon = 8
  if (text ~ /Sep/ ) mon = 9
  if (text ~ /Oct/ ) mon = 10
  if (text ~ /Nov/ ) mon = 11
  if (text ~ /Dec/ ) mon = 12

  if (mon == 0) {
    Error(sprintf("BAD month %s\n",text),3);
  }
  return mon;
}

time_stamp()

Ok now we have month() we can use function time_stamp() to covert text given by date in linux script output into a number of seconds. Gawk will give the elapsed number of seconds between two such calls of date by simple subtraction.

time_zone_index refers to the location of date's output on the current line being processed by gawk.

function time_stamp(time_zone_index,  n,t,u) {
  #eg Fri May 1 09:32:22 BST 2015
  #mktime uses YYYY MM DD HH MM SS [DST]"
  n=split($(time_zone_index-1),t,":");
  if(n!=3) Error(sprintf("Bad time `%s'",$(time_zone_index-1),2));
  u = sprintf("%s ",$(time_zone_index+1)); #year
  u = sprintf("%s%s ",u,month($(time_zone_index-3)));
  u = sprintf("%s%s ",u,$(time_zone_index-2)); #day
  u = sprintf("%s%s ",u,t[1]);   #hour
  u = sprintf("%s%s ",u,t[2]);   #minutes
  u = sprintf("%s%s ",u,t[3]);   #seconds
  u = sprintf("%s%s", u,$time_zone_index); #eg BST or GMT
  return mktime(u);
}

Example

E.g. log file:
gcat.bat $Revision: 1.6 $ Sun May 3 13:50:32 BST 2015
........
gcat.bat sam done  Sun May 3 14:05:09 BST 2015
Gawk script fragments:
  start = time_stamp(9);
  end = time_stamp(8);
  print "elapsed seconds",end-start;
Output:
elapsed seconds 877

W.B.Langdon Back 1 May 2015 (Last update 3 May)