sql - Converting Seconds into Total Hours:minutes:seconds -
can guide me on how convert seconds total hours, minutes , seconds format?
for example: 2,652,819 secs should give 736:53:39
i able same in days:hours:minutes:seconds
format require convert days total hours
assuming you've got integral value tot_secs
— floating point require judicious use of round()
, ceil()
and/or floor()
, can try this:
select hours = ( t.tot_secs / 3600 ) , -- hours total seconds / (secs/hr) minutes = ( t.tot_secs % 3600 ) / 60 , -- minutes whatever's left on / 60 seconds = t.tot_secs % 60 , -- whatever's left on seconds hh_mm_ss = convert(varchar, t.tot_secs / 3600 ) + ':' + right( '0' + convert(varchar, ( t.tot_secs % 3600 ) / 60 ) , 2 ) + ':' + right( '0' + convert(varchar, t.tot_secs % 60 ) , 2 ) ( select tot_secs = 2652819 ) t
the above query yields
hours minutes seconds hh_mm_ss ----- ------- ------- -------- 736 53 39 736:53:39
Comments
Post a Comment