MariaDB SEC_TO_TIME() Function
In MariaDB, SEC_TO_TIME() is a built-in function that returns a time value converted from a given number of seconds.
MariaDB SEC_TO_TIME() Syntax
This is the syntax of the MariaDB SEC_TO_TIME() function:
SEC_TO_TIME(seconds)
Parameters
seconds-
Required. seconds.
If you supply the wrong number of arguments, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'SEC_TO_TIME'.
Return value
The MariaDB SEC_TO_TIME() function returns a time value in the HH:MM:SS.uuuuuu format.
If the argument is NULL, the SEC_TO_TIME() function will return NULL.
Note that MariaDB supports time ranges from '-838:59:59.999999' to '838:59:59.999999'.
MariaDB SEC_TO_TIME() Examples
Example 1
The following statement shows the basic usage of the MariaDB SEC_TO_TIME() function:
SELECT
SEC_TO_TIME(1),
SEC_TO_TIME(61),
SEC_TO_TIME(3661);
Output:
+----------------+-----------------+-------------------+
| SEC_TO_TIME(1) | SEC_TO_TIME(61) | SEC_TO_TIME(3661) |
+----------------+-----------------+-------------------+
| 00:00:01 | 00:01:01 | 01:01:01 |
+----------------+-----------------+-------------------+Example 2
MariaDB SEC_TO_TIME() allows you to use fractional seconds:
SELECT SEC_TO_TIME(3661.123456);
Output:
+--------------------------+
| SEC_TO_TIME(3661.123456) |
+--------------------------+
| 01:01:01.123456 |
+--------------------------+Example 3
MariaDB SEC_TO_TIME() allows you to use negative numbers, which will return a negative time value:
SELECT SEC_TO_TIME(-3661.123456);
Output:
+---------------------------+
| SEC_TO_TIME(-3661.123456) |
+---------------------------+
| -01:01:01.123456 |
+---------------------------+Example 4
MariaDB supports time ranges from '-838:59:59.999999' to '838:59:59.999999'.
If you provide a number outside the time range, MariaDB will only return the upper or lower value:
SELECT
SEC_TO_TIME(12345678),
SEC_TO_TIME(22345678);
Output:
+-----------------------+-----------------------+
| SEC_TO_TIME(12345678) | SEC_TO_TIME(22345678) |
+-----------------------+-----------------------+
| 838:59:59 | 838:59:59 |
+-----------------------+-----------------------+In this example, we used 2 large values ββand they both returned the largest time value.
Conclusion
In MariaDB, SEC_TO_TIME() is a built-in function that returns a time value converted from a given number of seconds.