haidarvm
haidarvm

Reputation: 630

PHP How to SUM time data from Mysql

I want to SUM total Time from Each Vehicle

Date        End Time
BMW120
2014-03-03  01:53:48
2014-03-03  01:54:28
2014-03-03  01:58:08
2014-03-03  01:59:08
2014-03-03  02:00:08
Mercy123
2014-03-03  01:55:08
2014-03-03  01:55:28
2014-03-03  01:55:48
2014-03-03  01:58:28
Mitsubishi
2014-03-03  01:54:08
2014-03-03  01:54:48
2014-03-03  01:56:08
2014-03-03  01:56:28

i modify the vehicle to show only once in foreach loop but now how to SUM Total time Each vehicle_id and Each Date Should i store in Array but how ?

Upvotes: 0

Views: 376

Answers (1)

Tau
Tau

Reputation: 468

You can get the total directly from database. You can use something like this to find out sum as seconds

SELECT custom_id, Date, SUM(TIME_TO_SEC(EndTime)) AS totalTime
FROM your_table GROUP BY Date, custom_id

or you can use this to get it in HH:MM:SS format

SELECT custom_id, Date, SEC_TO_TIME(SUM(TIME_TO_SEC(EndTime))) AS totalTime
FROM your_table GROUP BY Date, custom_id

Upvotes: 1

Related Questions