Page 1 of 1

How to calculate Time Duration in Calculated Field?

Posted: 2020-06-16 10:04
by tkietboi
Hi,

I'm having this situation, I wanna calculate
totalTime = endDate - startDate
Screenshot here: https://drive.google.com/file/d/1cG-p8N ... p=drivesdk

My calculated field now of totalTime, Data type is Time

Code: Select all

SELECT * , SEC_TO_TIME(TIMESTAMPDIFF(HOUR,`timesheet`.`endDate`,`timesheet`.`startDate`) *60) as `timesheet`.`totalTime`
FROM `timesheet`
Did I do something wrong?

Thank you for your helping!

Re: How to calculate Time Duration in Calculated Field?

Posted: 2020-06-16 19:21
by pbottcher
Hi,
if I see that correctly you try to convert minutes instead of seconds, next you only need to return one value from the SQL query and you should apply the query to the record id.

So you might try

Code: Select all

SELECT SEC_TO_TIME(TIMESTAMPDIFF(HOUR,`timesheet`.`endDate`,`timesheet`.`startDate`) *60*60) as `totalTime`
FROM `timesheet` WHERE ID=%ID%
Assuming that your PK field is ID.

Re: How to calculate Time Duration in Calculated Field?

Posted: 2020-06-17 04:51
by tkietboi
Yeahhh yesterday I already did with this

Code: Select all

SELECT SEC_TO_TIME(TIMESTAMPDIFF(SECOND,`timesheet`.`startDate`,`timesheet`.`endDate`))
FROM `timesheet`
WHERE `timesheet`.`id`='%ID%'
But anyway, thank you for your supporting.
This will note for me and anyone need after that!