Page 1 of 1

Timetracker using Calculated Fields

Posted: 2021-02-25 00:33
by hgarbe
Hi everybody,

I wanted to create a Timetracker to document time spent on different things. I found a partially working solution, but it has a bug. As I just got a very basic understanding of SQL I hope someone can give me a hint how to handle it.
I have two tables. Table 1 (itm_timetracker) is calcuating the timedifference between 2 datetime fields using this code:

Code: Select all

SELECT TIME_FORMAT(TIMEDIFF(`itm_timetracker`.`end_time`, `itm_timetracker`.`start_time`), '%H:%i') FROM `itm_timetracker` 
WHERE `itm_timetracker`.`id`='%ID%'
This code works and is displaying the Timediff in the way I wanted it to be.
timediff.png
timediff.png (3.34 KiB) Viewed 2020 times
The calculated Field in the second Table uses the code below so sum up all Timediffs based on an associated Task ID.

Code: Select all

SELECT TIME_FORMAT(SUM(`itm_timetracker`.`time_consumption`), '%H:%i') FROM `itm_timetracker` 
WHERE `itm_timetracker`.`associated_task`='%ID%'
Works fine until the sum of minutes exceeds 59 or in other words is more than one hour. As said I'm still working my way through SQL so any help appreciated!

Re: Timetracker using Calculated Fields

Posted: 2021-02-26 22:04
by pbottcher
Hi,

try

Code: Select all

SELECT TIME_FORMAT(SEC_TO_TIME(SUM(Time_TO_SEC(`itm_timetracker`.`time_consumption`)))), '%H:%i') FROM `itm_timetracker` 
WHERE `itm_timetracker`.`associated_task`='%ID%'

Re: Timetracker using Calculated Fields

Posted: 2021-03-01 00:06
by hgarbe
Thanks alot pbötter!
For taking the time to respond and at the same time solving the problem!
So the simply way was just to convert it to seconds, sum it up and then reconvert it?

Re: Timetracker using Calculated Fields

Posted: 2021-03-01 06:54
by pbottcher
Yep, true