Convert seconds to hh:mm:ss

Is there any built-in function that converts seconds into hh:mm:ss .
Note : time format should strictly follow hh:mm:ss format and I know same can be obtained by division

If always less than 24 hours, you could use millis_to_str, e.g. 120 seconds:

SELECT millis_to_str(120*1000-3600000,"%T");

  • Convert to milliseconds (*1000)
  • Subtract the base Epoch time (1 hour)
  • Print only the time component

If you’re looking for a general “any number of seconds to hours:minutes:seconds” function then no, there isn’t one and you’d have to do the division yourself. (Likely write your own UDF to do it.)

2 Likes

Just FYI, https://issues.couchbase.com/browse/MB-54506 which will be available in a future release adds "%#" formatting to the date functions permitting you to format a number of milliseconds from the epoch (i.e. 0) as …h:mm:ss. (If you have a number of seconds then, e.g. millis_to_str(field*1000,'%#') would achieve the requested formatting.)

1 Like