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

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of 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 from a starting stage. As well as demo example.

Leave a Reply

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