SQL Tutorial SQL Advanced SQL Database SQL References

MySQL MICROSECOND() Function



The MySQL 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.

mysql> SELECT MICROSECOND('2018-08-18');
Result: 0

mysql> SELECT MICROSECOND('2018-08-18 10:38:42');
Result: 0

mysql> SELECT MICROSECOND('2018-08-18 10:38:42.000004');
Result: 4

mysql> SELECT MICROSECOND('2018-08-18 10:38:42.999999');
Result: 999999

mysql> SELECT MICROSECOND("838:11:59.001234");
Result: 1234

Example 2:

Consider a database table called Orders with the following records:

OrderQuantityPriceOrderTime
1001.582017-08-18 10:38:42.000004
1201.612018-03-23 07:14:16
1251.782018-09-12 05:25:56.000566
501.802019-01-16 11:52:05.001234
2001.722020-02-06 09:31:34.006789

The query 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:

OrderQuantityPriceOrderTimeMICROSECOND_Value
1001.582017-08-18 10:38:42.0000044
1201.612018-03-23 07:14:160
1251.782018-09-12 05:25:56.000566566
501.802019-01-16 11:52:05.0012341234
2001.722020-02-06 09:31:34.0067896789

❮ MySQL Functions

5