Summary: in this tutorial, you will learn how to use the MySQL TIME_TO_SEC() function to convert a time argument to seconds.
Introduction MySQL TIME_TO_SEC() function
The TIME_TO_SEC() function converts a time argument to seconds. Here’s the syntax of the TIME_TO_SEC() function:
TIME_TO_SEC(time)Code language: SQL (Structured Query Language) (sql)In this syntax:
time: This is thetimeargument that you want to convert to seconds.
The TIME_TO_SEC() function returns the seconds converted from the time argument. If the time is NULL, the TIME_TO_SEC() function returns NULL.
MySQL TIME_TO_SEC() function example
The following example uses the TIME_TO_SEC() function to convert a time argument to seconds:
SELECT TIME_TO_SEC('00:05:30');Code language: SQL (Structured Query Language) (sql)Output:
+-------------------------+
| TIME_TO_SEC('00:05:30') |
+-------------------------+
| 330 |
+-------------------------+
1 row in set (0.00 sec)Code language: SQL (Structured Query Language) (sql)In this example, we use the TIME_TO_SEC() function to convert a time ( 5 minutes and 30 seconds) to seconds, which results in 330 seconds.
Summary
- Use the
TIME_TO_SEC()function to convert a time to seconds.
Was this tutorial helpful?