Home »
MySQL »
MySQL date/time Functions
MySQL MICROSECOND() Function
MySQL | MICROSECOND() Function: Learn about the MICROSECOND() function, how it works, its usages, syntax, and examples.
Submitted by Apurva Mathur, on October 10, 2022
MICROSECOND() Function
We know that in MySQL, we have different formats to store time, sometimes only the "hh:mm:ss" format is used to store time and sometimes we use the format which keeps the record about the microseconds also, so to only fetch the microsecond part from the given time we use MICROSECOND() function. This function helps us to get the microsecond part from the given time.
MICROSECOND() Syntax
SELECT MICROSECOND('datetime');
MICROSECOND() Parameter(s)
- It takes only one parameter which is datetime value.
MICROSECOND() Return Value
As a result, it will display the microsecond part from the time that you have provided.
MySQL MICROSECOND() Function Example 1
SELECT MICROSECOND('20:11:05.00007');
MySQL MICROSECOND() Function Example 2
SELECT MICROSECOND('2002-5-18 20:11:05.000078');
But if the datetime value which you are writing as a parameter doesn't include any microsecond part then in such case, it will show you 0 or NULL.
MySQL MICROSECOND() Function Example 3
SELECT MICROSECOND('2002-5-18 20:11:05');
As you can see the above example doesn’t include any microsecond part which is why the result displayed is 0.