SEC_TO_TIME( )

This MySQL function returns the period for a given number of seconds in the format hh:mm:ss.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

SEC_TO_TIME(seconds)

Explanation

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.

Examples

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 | 
+-------------+----------------+

In this example, we've given a value of 3600 seconds, which the function has formatted to show one 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 one day's worth, the value for hours will result in an amount greater than 23 and will not be reset back to 0.