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);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;Limit of 838 hours
MySQL 8.1
SELECT SEC_TO_TIME(4000000);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.