MariaDB SEC_TO_TIME() Function
The MariaDB SEC_TO_TIME() function returns a time value (in format HH:MM:SS) based on the specified seconds. A time value (returned value) can range from '-838:59:59' to '838:59:59'.
Syntax
SEC_TO_TIME(seconds)
Parameters
seconds |
Required. Specify the number of seconds. Both positive or negative values are allowed. |
Return Value
Returns the time value (in format HH:MM:SS) based on the specified seconds.
Example 1:
The example below shows the usage of SEC_TO_TIME() function.
SELECT SEC_TO_TIME(50); Result: '00:00:50' SELECT SEC_TO_TIME(500); Result: '00:08:20' SELECT SEC_TO_TIME(10000); Result: '02:46:40' SELECT SEC_TO_TIME(423456); Result: '117:37:36' SELECT SEC_TO_TIME(-423456); Result: '-117:37:36'
Example 2:
Consider a database table called Sample with the following records:
Data | Seconds |
---|---|
Data 1 | 25789 |
Data 2 | 35909 |
Data 3 | 30144 |
Data 4 | 24003 |
Data 5 | 44321 |
The statement given below can be used to get the time value by converting the records of column Seconds.
SELECT *, SEC_TO_TIME(Seconds) AS SEC_TO_TIME_Value FROM Sample;
This will produce the result as shown below:
Data | Seconds | SEC_TO_TIME_Value |
---|---|---|
Data 1 | 25789 | 07:09:49 |
Data 2 | 35909 | 09:58:29 |
Data 3 | 30144 | 08:22:24 |
Data 4 | 24003 | 06:40:03 |
Data 5 | 44321 | 12:18:41 |
❮ MariaDB Functions