MySQL MICROSECOND() function; In this tutorial, i am going to show you MySQL microsecond() function with the help of examples.
MySQL MICROSECOND() Function
The MySQL Microsecond() function is used to return the microsecond part for a specified time or date-time value. The range of microsecond value is from 0 to 999999. For example, if the specified time is “09:12:23.000123”, this function will return 123 microseconds.
Syntax of MySQL MICROSECOND() Function
The syntax of this microsecond() is:
MICROSECOND(time)
Here, time is the value you want to remove from the microsecond component.
Example 1 – MySQL MICROSECOND() Function
Let’s take an example using MySQL microseconds() function; as follows:
SELECT MICROSECOND('09:40:00.123456');
Output-1
+--------------------------------+ | MICROSECOND('09:40:00.123456') | +--------------------------------+ | 123456 | +--------------------------------+
Example 2 – MySQL MICROSECOND() Function
Let’s take an example with microsecond() function using an abbreviated DateTime value; as follows:
SELECT MICROSECOND('2021-10-07 09:40:00.123456');
Output-2
+-------------------------------------------+ | MICROSECOND('2021-10-07 09:40:00.123456') | +-------------------------------------------+ | 123456 | +-------------------------------------------+
Example 3 – MySQL MICROSECOND() Function
Let’s take an example using the microsecond with last two digits are the only nonzero digits; as follows:
SELECT MICROSECOND('09:40:00.000056');
Output-3
+--------------------------------+ | MICROSECOND('09:40:00.000056') | +--------------------------------+ | 56 | +--------------------------------+
Example 4 – MySQL MICROSECOND() Function
To EXTRACT () function to extract microseconds (and other date/time parts) by date or time; as follows:
SELECT EXTRACT(MICROSECOND FROM '09:40:00.123456');
Output-4
+---------------------------------------------+ | EXTRACT(MICROSECOND FROM '09:40:00.123456') | +---------------------------------------------+ | 123456 | +---------------------------------------------+
Conclusion
MySQL MICROSECOND() Function tutorial, you have learned how to use MySQL MICROSECOND() function with various examples.