SECOND() Function Examples – MySQL

We would love to share with you how to works the second() function of mysql. We will make a list of examples below.

MySQL SECOND() Function

In MySQL, SECOND()  the function is used to return the second component from a time value.

Note: This function pass only one parameter and it will return value seconds of given time within the range 0 to 59.

Syntax

The syntax of the second() of MySQL is below:

SECOND(time)

Here,time is the time value that you want to extract the seconds component from.

Example-1

Let’s take a basic example of a second() function is below:

SELECT SECOND('10:35:29');

Output-1

+--------------------+
| SECOND('10:35:29') |
+--------------------+
|                 29 |
+--------------------+

Example-2

Here’s, We take the second example using an abbreviated time value without colons.

SELECT SECOND('1220');

Output-2

+----------------+
| SECOND('1220') |
+----------------+
|             20 |
+----------------+

Example-3

You can also use the EXTRACT () function to extract seconds (and other date / time parts) from the date / time value:

SELECT EXTRACT(SECOND FROM '10:35:27');

Output-3

+---------------------------------+
| EXTRACT(SECOND FROM '10:35:45') |
+---------------------------------+
|                              45 |
+---------------------------------+

Example-4

We take a another example of second() function with NOW() function is below:

SELECT SECOND(NOW());
+----------------+
| SECOND(NOW())  |
+----------------+
|             10 |
+----------------+

Let’s look at some more MySQL SECOND() examples and explore how to use the SECOND() in MySQL. See the below more examples :

mysql> SELECT SECOND('2014-01-28 07:47:18.000004');
Result: 18

mysql> SELECT SECOND('2014-01-28 15:21:05');
Result: 5

mysql> SELECT SECOND('12:13:06');
Result: 6

mysql> SELECT SECOND('838:11:59');
Result: 59

Conclusion

Here, you have learned how to use MySQL SECOND() function with various examples.

If you have any questions or thoughts to share, use the comment form below to reach us.

Spread the love

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *