This is my query:
SELECT TIMEDIFF(end_time,start_time) AS \"total\" FROM `metrics`;
which gives me:
116:12:10
The easiest way to do this is
CONCAT(
FLOOR(TIMESTAMPDIFF(SECOND, startDate, endDate) / 86400), ' days ',
FLOOR((TIMESTAMPDIFF(SECOND, startDate, endDate) % 86400)/3600), ' hours ',
FLOOR((TIMESTAMPDIFF(SECOND, startDate, endDate) % 3600)/60), ' minutes ',
(TIMESTAMPDIFF(SECOND, startDate, endDate) % 60), ' seconds'
)
To show only relevant information you'd need to do a more complex version
IF(
FLOOR(TIMESTAMPDIFF(SECOND, startDate, endDate) / 86400) = 0,
IF(
FLOOR((TIMESTAMPDIFF(SECOND, startDate, endDate) % 86400)/3600) = 0,
IF(
FLOOR((TIMESTAMPDIFF(SECOND, startDate, endDate) % 3600)/60) = 0,
CONCAT((TIMESTAMPDIFF(SECOND, startDate, endDate) % 60), ' seconds'),
CONCAT(
FLOOR((TIMESTAMPDIFF(SECOND, startDate, endDate) % 3600)/60), ' minutes ',
(TIMESTAMPDIFF(SECOND, startDate, endDate) % 60), ' seconds'
)
),
CONCAT(
FLOOR((TIMESTAMPDIFF(SECOND, startDate, endDate) % 86400)/3600), ' hours ',
FLOOR((TIMESTAMPDIFF(SECOND, startDate, endDate) % 3600)/60), ' minutes ',
(TIMESTAMPDIFF(SECOND, startDate, endDate) % 60), ' seconds'
)
),
CONCAT(
FLOOR(TIMESTAMPDIFF(SECOND, startDate, endDate) / 86400), ' days ',
FLOOR((TIMESTAMPDIFF(SECOND, startDate, endDate) % 86400)/3600), ' hours ',
FLOOR((TIMESTAMPDIFF(SECOND, startDate, endDate) % 3600)/60), ' minutes ',
(TIMESTAMPDIFF(SECOND, startDate, endDate) % 60), ' seconds'
)
)