MariaDB MICROSECOND() Function

In MariaDB, MICROSECOND() is a built-in function that extracts the microsecond portion of a time or datetime and returns it as a number.

MariaDB MICROSECOND() Syntax

This is the syntax of the MariaDB MICROSECOND() function:

MICROSECOND(time)

Parameters

time

Required. A time or datetime expression.

Return value

The MariaDB MICROSECOND() function extracts the microsecond portion of a time or datetime and returns it as a number. The return value of the MICROSECOND() function is a number between 0 and 999999.

If the argument is NULL, the MICROSECOND() function will return NULL.

MariaDB MICROSECOND() Examples

Example 1

This statement shows the basic usage of the MariaDB MICROSECOND() function:

SELECT
    MICROSECOND('10:11:12.111334'),
    MICROSECOND('2022-02-28 10:11:12.000334'),
    MICROSECOND('2022-02-28')\G

Output:

           MICROSECOND('10:11:12.111334'): 111334
MICROSECOND('2022-02-28 10:11:12.000334'): 334
                MICROSECOND('2022-02-28'): 0

Example 2

You can pass NOW() as the parameter to get fractional seconds of the current time:

SELECT
    NOW(6),
    MICROSECOND(NOW(6));

Output:

+----------------------------+---------------------+
| NOW(6)                     | MICROSECOND(NOW(6)) |
+----------------------------+---------------------+
| 2023-01-10 11:48:31.055509 |               55509 |
+----------------------------+---------------------+

Conclusion

In MariaDB, MICROSECOND() is a built-in function that extracts the microsecond portion of a time or datetime and returns it as a number.