How to caculate sum of times of my colonne called "timeSpent" having this format: HH:mm in SQL? I am using MySQL.
the type of my column is Time.
it has this structure
TimeFrom like 10:00:00 12:00:00 02:00:00 TimeUntil 08:00:00 09:15:00 01:15:00 Time spent total time 03:15:00
The aggregate function SUM is ideal for computing the sum of a column's values. This function is used in a SELECT statement and takes the name of the column whose values you want to sum. If you do not specify any other columns in the SELECT statement, then the sum will be calculated for all records in the table.
SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( `timeSpent` ) ) ) AS timeSum FROM YourTableName
This worked for me. Hope this helps.
100% working code to get sum of time out of MYSQL Database:
SELECT SEC_TO_TIME( SUM(time_to_sec(`db`.`tablename`))) As timeSum FROM `tablename`
Try and confirm. Thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With