In MariaDB, MICROSECOND() is a built-in date and time function that returns the microseconds portion of a given time expression.
It accepts one argument, which is the time you want to extract the microseconds from.
The seconds are returned as a number in the range 0 to 999999.
Syntax
The syntax goes like this:
MICROSECOND(time)
Where time is the time expression to get the microseconds from.
Example
Here’s an example:
SELECT MICROSECOND('10:30:45.123456');
Result:
+--------------------------------+
| MICROSECOND('10:30:45.123456') |
+--------------------------------+
| 123456 |
+--------------------------------+
The following time expression doesn’t explicitly include microseconds:
SELECT MICROSECOND('10:30:45');
Result:
+-------------------------+
| MICROSECOND('10:30:45') |
+-------------------------+
| 0 |
+-------------------------+
So the result is 0.
Datetime Values
It also works with datetime values:
SELECT MICROSECOND('2030-02-01 10:30:45.123456');
Result:
+-------------------------------------------+
| MICROSECOND('2030-02-01 10:30:45.123456') |
+-------------------------------------------+
| 123456 |
+-------------------------------------------+
Date Values
Passing a date without a time returns 0, along with a warning.
Example:
SELECT MICROSECOND('2025-10-31');
Result:
+---------------------------+
| MICROSECOND('2025-10-31') |
+---------------------------+
| 0 |
+---------------------------+
1 row in set, 1 warning (0.001 sec)
We can see the warning by running the following code:
SHOW WARNINGS;
Result:
+---------+------+----------------------------------------------+ | Level | Code | Message | +---------+------+----------------------------------------------+ | Warning | 1292 | Truncated incorrect time value: '2025-10-31' | +---------+------+----------------------------------------------+
Current Date
We can pass NOW() as the datetime argument to use the current time:
SELECT
NOW(6),
MICROSECOND(NOW(6));
Result:
+----------------------------+---------------------+ | NOW(6) | MICROSECOND(NOW(6)) | +----------------------------+---------------------+ | 2021-05-16 14:41:09.098168 | 98168 | +----------------------------+---------------------+
In this case I specified that NOW() should return a fractional precision of 6 (which makes it return microseconds).
Here it is again with a lower precision:
SELECT
NOW(3),
MICROSECOND(NOW(3));
Result:
+-------------------------+---------------------+ | NOW(3) | MICROSECOND(NOW(3)) | +-------------------------+---------------------+ | 2021-05-16 14:42:35.831 | 831000 | +-------------------------+---------------------+
Invalid Arguments
When passed an invalid time argument, MICROSECOND() returns null:
SELECT MICROSECOND('10:75:00.123456');
Result:
+--------------------------------+
| MICROSECOND('10:75:00.123456') |
+--------------------------------+
| NULL |
+--------------------------------+
Missing Argument
Calling MICROSECOND() with the wrong number of arguments, or without passing any arguments, results in an error:
SELECT MICROSECOND();
Result:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
And another example:
SELECT MICROSECOND('10:30:45.123', '06:30:45.123');
Result:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' '06:30:45.123')' at line 1