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. Here is an example:
SELECT SEC_TO_TIME(3600) AS 'Time Format', SEC_TO_TIME(3600) + 0 AS 'Numeric Format'; +-------------+----------------+ | Time Format | Numeric Format | +-------------+----------------+ | 01:00:00 | 10000.000000 | +-------------+----------------+
We’ve given a value of 3,600 seconds, which the function formats to show as 1 hour in the first field. The next field shows the same results, but in numeric format and with microseconds included. If the number of seconds exceeds 86,400, or 1 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, 2nd Edition 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.