MySQL MICROSECOND() Function

The MICROSECOND() function extracts and returns the microsecond part of a time or datetime value as an integer (ranging from 0 to 999999).


Definition and Usage

  • This function is used to extract the fractional second part (microseconds) of a given time or datetime.

Syntax

MICROSECOND(datetime)

Parameter Values

Parameter Description Requirement
datetime The time or datetime value to extract microseconds from Required

Examples

Example 1: Extract microseconds from a datetime value

SELECT MICROSECOND("2017-06-20 09:34:00.000023");

Output:

23

Example 2: Extract microseconds from a time value

SELECT MICROSECOND("23:59:59.000045");

Output:

45

Example 3: Extract microseconds from a value without fractional seconds

SELECT MICROSECOND("2024-12-29 15:45:10");

Output:

0

Example 4: Extract microseconds from the current timestamp

SELECT MICROSECOND(CURRENT_TIMESTAMP(6));

Output: Returns the microsecond part of the current timestamp with six decimal places of precision (e.g., 123456).


Technical Details

  • Works in MySQL versions: From MySQL 4.0.
  • Return Type: Integer value ranging from 0 to 999999.

Notes:

  • The function works only with time/datetime values that include fractional seconds. If no fractional seconds are present, the function returns 0.

Was this article helpful?