Start a conversation

Calculating the difference between times

Example of PHP code that get the difference between time:


FUNCTION h2m($hours) { 

$t = EXPLODE(":", $hours);
$h = $t[0];
IF (ISSET($t[1])) {
$m = $t[1]; 
} ELSE {
$m = "00"; 
}
$mm = ($h * 60)+$m;
RETURN $mm; 



FUNCTION m2h($minute) { 

$hs=$minute/60;
$t=explode('.', $hs);
$h=$t[0];
IF (ISSET($t[1])) {
$ms = $hs-$h;
$m=$ms*60; 
} ELSE {
$m = "00"; 
}
if ($h<10) {
RETURN "0".$h.":".$m.":00";
} else {
RETURN $h.":".$m.":00";
}





if ({second}<{first}) { sc_error_message("Wrong value in input");}
sc_error_exit();


$first_to_minute=h2m({first});
$second_to_minute=h2m({second});

$result_m=$second_to_minute-$first_to_minute;
{result}=m2h($result_m);

Choose files or drag and drop files
Was this article helpful?
Yes
No
  1. Amanda Santos (Migrated deleted Agent)

  2. Posted
  3. Updated

Comments