Reputation: 2035
I have this query:
SELECT sum(TIMEDIFF(`time_out`, `time_in`)) as `total` FROM `user_log` WHERE `uid` = '1' AND `time_out` <> '0000-00-00 00:00:00'
Then I calculate the seconds to hours:
$total_difference = (($difference->total) / 60 / 60);
But this is showing me 22,352125 hours, which is impossible...
I've been testing and I have 2 records showing up if I don't use SUM:
SELECT TIMEDIFF(`time_out`, `time_in`) as `total` FROM `user_log` WHERE `uid` = '1' AND `time_out` <> '0000-00-00 00:00:00'
This result is far below the 22 hours I get when I use SUM in my query. Any help? I don't know what I'm doing wrong.
Thanks!
Upvotes: 1
Views: 81
Reputation: 3833
Can adjust the query to use TIME_TO_SEC - this will convert the return value of TIMEDIFF to a numeric number of seconds, which can sensibly be summed
adjusted query
SELECT SUM(TIME_TO_SEC(TIMEDIFF(time_out, time_in))) as total
FROM user_log
WHERE uid = '1' AND time_out <> '0000-00-00 00:00:00'
;
Upvotes: 3