开发者

Converting Integer into time value, using SQL

So I am using the following SQL search to add all time values in a database in the hours field of the logbook database:

SELECT SUM(hours) FROM logbook

But there is a problem as I recieve the output:

SUM(hours)
48514

Which is almost there!

What I really need it to do is this:

04:85:14

Which is in HH:MM:SS

and then from there, recognise that the MM is > 59 and therefore round the HH up by one, and in sa开发者_如何学Goying this prepare to do this to all of the 3 sections: HH MM SS.

But I have no idea how to do this!

Thanks for the help guys!


I think you should be able to do this inside the query, but if you for some reason have to use php you could try this:

$hours = 48514;
function detailedHours($hours) {
    $hour = substr($hours,0,1);
    $minutes = substr($hours,1,2);
    $seconds = substr($hours,3,2);
    while($seconds>59) {
        $minutes++;
        $seconds-=60;
    }
    while($minutes>59) {
        $hour++;
        $minutes-=60;
    }
    return "$hour:$minutes:$seconds";
}
echo detailedHours($hours);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜