-2

Struggling with this!

I need a sum of all the diffs in php so here's the source

$du = mysql_query("select SUBTIME(timeto,timefrom) as diff from table");

while($d = mysql_fetch_assoc($du))
{

    $total[] = strtotime($d["diff"]);

}

$t = array_sum($total);

echo gmdate("H:i", $t);

Before you say it... I know I should be using PDO or mysqli

Unfortunately I need the solution in PHP

1 Answers1

1
$du = mysql_query("SELECT SUM(TIME_TO_SEC(TIMEDIFF(timeto, timefrom))) AS TOTAL_SEC FROM table");

$d = mysql_fetch_assoc($du);

echo gmdate("H:i", $d["TOTAL_SEC"]);
Simone Nigro
  • 4,717
  • 2
  • 37
  • 72