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