############################################ # Function: TimeDiff ############################################ # param1 is the 'from' DateTime as 'YYYY-MM-DD HH:MM:SS' 24-hour clock # param2 is the 'to' Date as 'YYYY-MM-DD HH:MM:SS' 24 hour-clock # returns time difference in seconds sub timeDiff { my (@fromDT, @toDT); my (@fromT, @toT); my ($fromTM, $toTM); if(!defined($_[0]) || !defined($_[1])){ return(1); } @fromDT = split(/ /,$_[0]); @toDT = split(/ /,$_[1]); @fromT = split(/:/,$fromDT[1]); @toT = split(/:/,$toDT[1]); $fromTM = ($fromT[0] * 3600) + ($fromT[1] * 60) + $fromT[2]; $toTM = ($toT[0] * 3600) + ($toT[1] * 60) + $toT[2]; # If fromDT is different than toDT we make the assumption that either the data is corrupt or the transaction ran over midnight if($fromDT[0] ne $toDT[0]){ my @fromDate = split(/-/,$fromDT[0]); my @toDate = split(/-/,$toDT[0]); if( ($fromDate[0] eq $toDate[0]) && ($fromDate[1] eq $toDate[1]) && ( ($toDate[2] - $fromDate[2]) == 1) ) { $toTM += (24 * 3600); } else { return; } } if(($toTM - $fromTM) == 0){ return(1); } return($toTM - $fromTM); }