Function Reference

SEC_TO_TIME

PostgreSQL equivalent:

Converts a number of seconds to a time.

MySQL 8.1
SEC_TO_TIME(seconds)

Parameters

secondsDECIMAL
Number of seconds, can be negative or fractional

Return value

A time (TIME) from -838:59:59 to 838:59:59; values outside the range are clipped

Examples

Seconds to time

MySQL 8.1
SELECT SEC_TO_TIME(3661);
SEC_TO_TIME(3661)
01:01:01

Total flight time

MySQL 8.1
SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(time_in, time_out)))) AS total_flight_time
FROM Trip;
total_flight_time
147:02:00

Limit of 838 hours

MySQL 8.1
SELECT SEC_TO_TIME(4000000);
SEC_TO_TIME(4000000)
838:59:59

Details

Fractional seconds are kept: SEC_TO_TIME(3661.5) returns 01:01:01.5. The limit of 838 hours is about 35 days, so for longer periods calculate the days separately: seconds DIV 86400.

See also