MySQL SECOND() Function

Summary: in this tutorial, you will learn how to use the MySQL SECOND() function to get the second for a time value.

Introduction to MySQL SECOND() function

The SECOND() function allows you to extract the second component of a time value.

Here’s the basic syntax of the SECOND() function:

SECOND(time)Code language: SQL (Structured Query Language) (sql)

In this syntax:

  • time: The time that you want to extract the second component. The time value has the data type is TIME.

The SECOND() function returns an integer that represents the second component of the time.

If the time represents the time of the day, the SECOND() function returns a value between 0 and 59. But if the time value is larger, the SECOND() function can return values greater than 59.

If the time is NULL, the SECOND() function returns NULL.

MySQL SECOND() function example

The following example uses the SECOND() function to get the second from the time '10:45:20':

SELECT SECOND('10:45:20');Code language: SQL (Structured Query Language) (sql)

Output:

+--------------------+
| SECOND('10:45:20') |
+--------------------+
|                 20 |
+--------------------+
1 row in set (0.00 sec)Code language: plaintext (plaintext)

Summary

  • Use the SECOND() function to get the second component of a specific time.
Was this tutorial helpful?