MySQL MICROSECOND() Function Examples

MySQL MICROSECOND() Function Examples

MySQL MICROSECOND() function; In this tutorial, We are going to demostrate to you how to use the MySQL microsecond() function with the help of examples.

MySQL MICROSECOND() Function

The MySQL MICROSECOND() function is used to return the microsecond component from a time value.

Note: This function return value for the range between 0 to 999999.

Syntax

The syntax of this microsecond() is:

MICROSECOND(time)

Here, time is the value you want to remove from the microsecond component.

Example-1

Let’s take an example, we will simple example with microseconds() function is:

SELECT MICROSECOND('09:40:00.123456');

Output-1

+--------------------------------+
| MICROSECOND('09:40:00.123456') |
+--------------------------------+
|                         123456 |
+--------------------------------+

Example-2

Let’s take an example with microsecond() function using an abbreviated DateTime value.

SELECT MICROSECOND('2021-10-07 09:40:00.123456');

Output-2

+-------------------------------------------+
| MICROSECOND('2021-10-07 09:40:00.123456') |
+-------------------------------------------+
|                                    123456 |
+-------------------------------------------+

Example-3

And here’s an example where the last two digits are the only nonzero digits.

SELECT MICROSECOND('09:40:00.000056');

Output-3

+--------------------------------+
| MICROSECOND('09:40:00.000056') |
+--------------------------------+
|                             56 |
+--------------------------------+

Example-4

You can use the EXTRACT () function to extract microseconds (and other date/time parts) by date or time:

SELECT EXTRACT(MICROSECOND FROM '09:40:00.123456');

Output-4

+---------------------------------------------+
| EXTRACT(MICROSECOND FROM '09:40:00.123456') |
+---------------------------------------------+
|                                      123456 |
+---------------------------------------------+

Conclusion

Here, you have learned how to use MySQL MICROSECOND() 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 *