MICROSECOND() Function Examples – MySQL

MICROSECOND() Function Examples – MySQL

In this MySQL tutorial, We are going to demostrate to you how to use the microsecond() function of MySQL. Here, we will take various types 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.

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. SECOND() 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.

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, Javascript, JQuery, Laravel, Livewire, Codeigniter, Vue JS, Angular JS, React Js, WordPress, 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 *