Name

SEC_TO_TIME( )

Synopsis

SEC_TO_TIME(seconds)

This function returns the period for a given number of seconds, in the format hh:mm:ss. It will return the time in hhmmss format if it’s used as part of a numeric calculation.

SELECT SEC_TO_TIME(3600)
       AS 'Actual Time';
+-------------+
| Actual Time |
+-------------+
| 01:00:00    |
+-------------+

In this example, we have a value of 3,600 seconds into the day, which the function has translated to 1 a.m. Incidentally, if the number of seconds exceeds 86,400, or one day’s worth, the value for hours will result in an amount greater than 23 and will not be reset back to 0.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.