unistake Posted January 30, 2010 Share Posted January 30, 2010 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 Link to comment https://forums.phpfreaks.com/topic/190396-sumtimes-in-hours-and-minutes/ Share on other sites More sharing options...
The Little Guy Posted January 30, 2010 Share Posted January 30, 2010 I found this on the mysql time page: SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( `time` ) ) ) AS total_time FROM time_table Link to comment https://forums.phpfreaks.com/topic/190396-sumtimes-in-hours-and-minutes/#findComment-1004370 Share on other sites More sharing options...
unistake Posted January 30, 2010 Author Share Posted January 30, 2010 thanks little guy, could you write this into my script above? That has totally lost me! Link to comment https://forums.phpfreaks.com/topic/190396-sumtimes-in-hours-and-minutes/#findComment-1004373 Share on other sites More sharing options...
The Little Guy Posted January 30, 2010 Share Posted January 30, 2010 <?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; } */ ?> Link to comment https://forums.phpfreaks.com/topic/190396-sumtimes-in-hours-and-minutes/#findComment-1004375 Share on other sites More sharing options...
unistake Posted January 30, 2010 Author Share Posted January 30, 2010 You are a legend! Works as it should, put my hours of attempts to a finish, thanks Big Man! Link to comment https://forums.phpfreaks.com/topic/190396-sumtimes-in-hours-and-minutes/#findComment-1004376 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.