MariaDB MICROSECOND() Function
The MariaDB MICROSECOND() function returns the microsecond portion of a given time or datetime value. It can be between 0 to 999999.
Syntax
MICROSECOND(datetime)
Parameters
datetime |
Required. Specify a time or datetime value from which to extract the microsecond. |
Return Value
Returns the microsecond part of a given time or datetime value.
Example 1:
The example below shows the usage of MICROSECOND() function.
SELECT MICROSECOND('2018-08-18'); Result: 0 SELECT MICROSECOND('2018-08-18 10:38:42'); Result: 0 SELECT MICROSECOND('2018-08-18 10:38:42.000004'); Result: 4 SELECT MICROSECOND('2018-08-18 10:38:42.999999'); Result: 999999 SELECT MICROSECOND("838:11:59.001234"); Result: 1234
Example 2:
Consider a database table called Orders with the following records:
OrderQuantity | Price | OrderTime |
---|---|---|
100 | 1.58 | 2017-08-18 10:38:42.000004 |
120 | 1.61 | 2018-03-23 07:14:16 |
125 | 1.78 | 2018-09-12 05:25:56.000566 |
50 | 1.80 | 2019-01-16 11:52:05.001234 |
200 | 1.72 | 2020-02-06 09:31:34.006789 |
The statement given below can be used to get the microsecond portion of records of column OrderTime:
SELECT *, MICROSECOND(OrderTime) AS MICROSECOND_Value FROM Orders;
This will produce the result as shown below:
OrderQuantity | Price | OrderTime | MICROSECOND_Value |
---|---|---|---|
100 | 1.58 | 2017-08-18 10:38:42.000004 | 4 |
120 | 1.61 | 2018-03-23 07:14:16 | 0 |
125 | 1.78 | 2018-09-12 05:25:56.000566 | 566 |
50 | 1.80 | 2019-01-16 11:52:05.001234 | 1234 |
200 | 1.72 | 2020-02-06 09:31:34.006789 | 6789 |
❮ MariaDB Functions