This comes from my previous question on getting the average time interval over a specified data set, [located here][1]. I\'ll post the entire function again:
fun
Hm, average difference in seconds, why that PHP swath of code if your database can give it to you:
SELECT
SEC_TO_TIME(MAX(TIME_TO_SEC(TIMEDIFF(end_time,start_time)))) AS max_timediff,
SEC_TO_TIME(MIN(TIME_TO_SEC(TIMEDIFF(end_time,start_time)))) AS min_timediff,
SEC_TO_TIME(AVG(TIME_TO_SEC(TIMEDIFF(end_time,start_time)))) AS avg_timediff,
SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(end_time,start_time)))) AS sum_timediff,
COUNT(id) as total_events
FROM atb_log
WHERE
siteID=:siteID
AND start_time > :fromDate
AND end_time < :toDate
Format those min/max/avg/sum of seconds as you like.