MySQL SECOND() Function with Example

MySQL SECOND() Function with Example

MySQL SECOND() function; In this tutorial, we would love to share with you how to use the MySQL second() function with the help of examples.

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.

Recommended MySQL Tutorials

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

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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