2

I'm trying to get a real life time based on seconds, where the number of seconds can be greater than 86400 (which equals 24 hours++). So for example; If the seconds equals 90000 the result will be 25:00:00, but instead I would like the output to be 01:00:00..

My logic is this:

IF seconds >= 86400
  // Add day of date +1
  // something similar to SEC_TO_TIME(seconds..). Need some help here
else
  SEC_TO_TIME(seconds)
GMB
  • 216,147
  • 25
  • 84
  • 135
robinmanz
  • 361
  • 1
  • 5
  • 17

2 Answers2

1

Using modulo:

sec_to_time(myvalue % 86400)

Demo on DB Fiddle:

with t as (select 12 myvalue union all select 9000)
select sec_to_time(myvalue % 86400) v from t
| v        |
| :------- |
| 00:00:12 |
| 02:30:00 |
ysth
  • 96,171
  • 6
  • 121
  • 214
GMB
  • 216,147
  • 25
  • 84
  • 135
0

Refer this answer

SELECT
           DATE_FORMAT(date('1970-12-31 23:59:59')
           + interval 86400 second,'%j days %Hh:%im:%ss') as result;
Ankit Sharma
  • 3,923
  • 2
  • 29
  • 49