MariaDB TIME_TO_SEC() Function
In MariaDB, TIME_TO_SEC()
is a built-in function that converts a given time value to seconds.
TIME_TO_SEC()
is the opposite of SEC_TO_TIME()
.
MariaDB TIME_TO_SEC()
Syntax
This is the syntax of the MariaDB TIME_TO_SEC()
function:
TIME_TO_SEC(time)
Parameters
time
-
Required. The time. Format:
HH:MM:SS
,HH:MM
, orSS
.
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 'TIME_TO_SEC'
.
Return value
The MariaDB TIME_TO_SEC()
function converts the specified time value to seconds.
If the argument is NULL
, the TIME_TO_SEC()
function will return NULL
.
MariaDB TIME_TO_SEC()
Examples
Example 1
The following statement shows the basic usage of the MariaDB TIME_TO_SEC()
function:
SELECT
TIME_TO_SEC('00:00:01') "00:00:01",
TIME_TO_SEC('00:01:01') "00:01:01",
TIME_TO_SEC('01:01:01') "01:01:01";
Output:
+----------+----------+----------+
| 00:00:01 | 00:01:01 | 01:01:01 |
+----------+----------+----------+
| 1 | 61 | 3661 |
+----------+----------+----------+
Example 2
MariaDB TIME_TO_SEC()
allows you to use fractional seconds:
SELECT TIME_TO_SEC('01:01:01.123456');
Output:
+--------------------------------+
| TIME_TO_SEC('01:01:01.123456') |
+--------------------------------+
| 3661.123456 |
+--------------------------------+
Example 3
MariaDB TIME_TO_SEC()
allows you to use negative numbers, which will return a negative time value:
SELECT TIME_TO_SEC('-01:01:01.123456');
Output:
+---------------------------------+
| TIME_TO_SEC('-01:01:01.123456') |
+---------------------------------+
| -3661.123456 |
+---------------------------------+
Conclusion
In MariaDB, TIME_TO_SEC()
is a built-in function that converts a given time value to seconds.