Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Best way to convert seconds to hours:minutes:seconds
Michel Cadot wrote:
> If your elapsed time does not exceed 24 hours (86400 seconds)
> you can use (with elapsed=81202 seconds):
>
> SQL> select to_char(to_date(81202,'SSSSS'),'HH24:MI:SS') elapsed from dual;
A simple extension to Michel's expression (which does the tricky part) will work for durations greater than 24 hours:
select decode(floor(999999/86400),
0, '', floor(999999/86400) || ' day(s), ') || to_char(to_date(mod(999999, 86400),'SSSSS'), 'HH24:MI:SS') AS elapsedfrom dual;
.. gives ...
ELAPSED
SQL> Substitute the column name for 999999 above. Note the above gives an undesirable result for NULL and breaks entirely for values < 0 (!)
--JH Received on Sat Dec 30 2006 - 14:24:36 CST
![]() |
![]() |