MySQL TIME_TO_SEC() Function

MySQL TIME_TO_SEC() function; In this tutorial, i am going to show you MySQL TIME_TO_SEC() function with the help of it’s syntax, parameters and examples.

MySQL TIME_TO_SEC() function

The MySQL TIME_TO_SEC function converts a time value into numeric seconds.

Syntax of MySQL TIME_TO_SEC() function

The syntax of MySQL TIME_TO_SEC() function; as follows:

TIME_TO_SEC(time)

Parameters of time_to_sec() function

ParameterDescription
timeIt accept single parameters and required. This is a time value.

Example 1 – Convert Time to Second

To convert a given time to second value using time_to_sec() function; as follows:

SELECT TIME_TO_SEC('00:05:00');

The output of the above query is the following:

 +-------------------------+
 | TIME_TO_SEC('00:05:00') |
 +-------------------------+
 |                     300 |
 +-------------------------+

Example 2 – Convert Hours to Second

To convert hours value to second value using time_to_sec() function:

SELECT TIME_TO_SEC('01:00:00');

The output of the above query is the following:

 +-------------------------+
 | TIME_TO_SEC('01:00:00') |
 +-------------------------+
 |                    3600 |
 +-------------------------+

Example 3 – Convert Current Time to Second

To convert current time to seconds; as follows:

SELECT 
   CURTIME() AS 'CurrentTime',
   TIME_TO_SEC(CURTIME()) AS 'Seconds';

The output of the above query is the following:

 +--------------+---------+
 | CurrentTime | Seconds  |
 +--------------+---------+
 | 08:22:25     |   30145 |
 +--------------+---------+

Conclusion

MySQL TIME_TO_SEC() function; In this tutorial,You have learned MySQL TIME_TO_SEC() function with the help of it’s syntax, parameters and examples.

Leave a Comment