SECOND() Function Examples – MySQL

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.

You may like

  1. TIMESTAMP() Function Examples – MySQL
  2. TIMEDIFF() Function Examples – MySQL
  3. SEC_TO_TIME() Function Examples – MySQL
  4. QUARTER() Function Examples – MySQL
  5. STR_TO_DATE() Function Examples – MySQL
  6. PERIOD_DIFF() Function Examples – MySQL
  7. PERIOD_ADD() Function Examples – MySQL
  8. MICROSECOND() Function Examples – MySQL
  9. MAKETIME() Function Examples – MySQL
  10. Localtime() Function Examples – MySQL
  11. CURTIME() Function Examples – MySQL
  12. MySQL CURRENT TIMESTAMP Function Examples
  13. MySQL CURRENT TIME Function Examples
  14. ADDTIME() Function Examples – MySQL
  15. MINUTE() Function Examples – MySQL
  16. HOUR() Function Examples – MySQL
  17. NOW() MySQL Function | MySQL
  18. MySQL DATE() And TIME() Functions (List)
  19. TIMESTAMPADD() Function Examples – MySQL
  20. TIMESTAMPDIFF() Function Examples – MySQL

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

Leave a Reply

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