DateTime::add adds hours even when interval should only be seconds

前端 未结 2 480
野性不改
野性不改 2021-01-24 20:34

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         


        
2条回答
  •  时光说笑
    2021-01-24 20:46

    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.

提交回复
热议问题