MySQL Tutorial MySQL Advanced MySQL Database Account Management MySQL References

MySQL TIME_TO_SEC() Function



The MySQL 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.

mysql> SELECT TIME_TO_SEC('00:00:50');
Result: 50

mysql> SELECT TIME_TO_SEC('00:08:20');
Result: 500

mysql> SELECT TIME_TO_SEC('02:46:40');
Result: 10000

mysql> SELECT TIME_TO_SEC('117:37:36');
Result: 423456

mysql> SELECT TIME_TO_SEC('-117:37:36');
Result: -423456

Example 2:

Consider a database table called Sample with the following records:

DataTime
Data 107:09:49
Data 209:58:29
Data 308:22:24
Data 406:40:03
Data 512: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:

DataTimeTIME_TO_SEC_Value
Data 107:09:4925789
Data 209:58:2935909
Data 308:22:2430144
Data 406:40:0324003
Data 512:18:4144321

❮ MySQL Functions