How to convert time in seconds to HH:MM:SS format in MySQL?

前端 未结 4 1824
太阳男子
太阳男子 2020-12-10 12:40

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

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 13:38

    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
    

提交回复
热议问题