I\'m having a data column named test_duration bigint(12). I\'m storing time in seconds into the database. Now when I fetch record from the table I want the
There is a MYSQL function that transform seconds to the format "HH:MM:SS":
SEC_TO_TIME(seconds)
Example:
SELECT SEC_TO_TIME(3661);
will output:
01:01:01
Regards
Do you store the time in Unixtime (Unix seconds?). If so, use:
FROM_UNIXTIME(unix_timestamp, '%h:%i:%s')
You can use MySQL function SEC_TO_TIME().
Example:
SELECT SEC_TO_TIME(2378);
Output is:
00:39:38
So in your case:
SELECT SEC_TO_TIME(test_duration) as `Time` FORM YOUR_TABLE;
The max value that you can get from the function SEC_TO_TIME is 838:59:59
If you have bigger number you can use this code:
SELECT DAY, Floor((SUM(DAY) / (60*60))) AS Hours,
Floor(MOD(SUM(DAY), (60*60)) / 60) AS Minutes,
Floor(MOD(SUM(DAY), (60))) AS Secs,
CONCAT(
Floor((SUM(DAY) / (60*60))), ":",
Floor(MOD(SUM(DAY), (60*60)) / 60), ":",
Floor(MOD(SUM(DAY), (60)))
) AS Time
FROM (SELECT 5328089 as DAY) a