Jump to content

SUM(times) in hours and minutes


unistake

Recommended Posts

Hi all,

I have several times in a mysql database stores as 00:25:00 = 25 minutes.

I am trying to add all the times up in a column under 'times' and show an output of 05:45  = 5 hours and 45 minutes (for example).

 

So far I have got...

<?
$query1 = "SELECT SUM(times) FROM logbook WHERE reg='1234'";
$result1 = mysql_query($query1) or die(mysql_error());

while($row = mysql_fetch_array($result1)){ 
   echo $row['SUM(times)'];
    echo $totalic;
}

?>

 

The output I get from the above $totalic is something like '34500'. - How can I convert this to 05:45 for example.

 

Thanks for the help guys :D

 

Link to comment
https://forums.phpfreaks.com/topic/190396-sumtimes-in-hours-and-minutes/
Share on other sites

<?php
$query1 = "SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(`times`))) AS total_time FROM logbook WHERE reg = '1234'";
//$query1 = "SELECT SUM(times) FROM logbook WHERE reg='1234'";
$result1 = mysql_query($query1) or die(mysql_error());
$row = mysql_fetch_assoc($result1);
echo $row['total_time'];

/*
while($row = mysql_fetch_array($result1)){ 
   echo $row['SUM(times)'];
    echo $totalic;
}
*/
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.