MySQL MICROSECOND() Function: Extract Microseconds from Date and Time

Learn how to use the MySQL `MICROSECOND()` function to extract the microsecond portion (0-999999) from DATETIME or TIME values. This guide provides a clear explanation of the function's syntax and offers practical examples demonstrating its use in MySQL queries for precise time-based calculations.



MySQL MICROSECOND() Function

Definition and Usage

The MICROSECOND() function in MySQL extracts the microsecond part of a DATETIME or TIME value. The microsecond value ranges from 0 to 999999.

Syntax

Syntax

MICROSECOND(datetime)
            

Parameter Values

Parameter Description
datetime Required. A DATETIME or TIME value from which to extract the microseconds.

Examples

Example 1: Extracting Microseconds from a DATETIME Value

This example extracts the microseconds from a DATETIME value.

SQL Query

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

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

Example 2: Extracting Microseconds from a TIME Value

This example demonstrates extracting microseconds from a TIME value.

SQL Query

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

MICROSECOND("23:59:59.000045")
-------------------------------------
45
            

Technical Details

The MICROSECOND() function is available in MySQL versions 4.0 and later.