MySQL MICROSECOND() Function
MySQL MICROSECOND() Function
The MySQL MICROSECOND() function extracts the fractional seconds from a TIME, DATETIME, or TIMESTAMP value. It returns an integer between 0 and 999999.
Modern applications often log API requests, payment events, and background jobs at sub-second precision. When two events happen within the same second, SECOND() treats them as identical. MICROSECOND() lets you inspect, sort, or audit events down to one-millionth of a second.
If your column has no fractional seconds defined, such as DATETIME instead of DATETIME(6), MICROSECOND() always returns 0.
Syntax
MICROSECOND(expr)
expr: A validTIME,DATETIME, orTIMESTAMPexpression, or a properly formatted string.
Practical Example
Suppose the demo_orders table stores high-precision checkout timestamps in paid_at using DATETIME(6). You can extract the microsecond component to inspect sub-second payment timing.
SELECT
order_id,
paid_at,
MICROSECOND(paid_at) AS paid_microseconds
FROM demo_orders
WHERE paid_at >= '2026-05-10 14:00:00'
ORDER BY paid_at;
| order_id | paid_at | paid_microseconds |
|---|---|---|
| 1041 | 2026-05-10 14:02:11.482000 | 482000 |
| 1042 | 2026-05-10 14:02:11.009125 | 9125 |
| 1043 | 2026-05-10 14:02:15 | 0 |
Notice how .482 expands to 482000 microseconds, while .009125 becomes 9125.
Common Mistakes & NULL Behavior
Developers often confuse milliseconds with microseconds. MySQL scales fractional digits to six places on the right. For example, '12:00:00.5' returns 500000, not 5.
Another frequent mistake is querying a plain DATETIME column expecting microsecond data. You must declare precision on the column, like DATETIME(3) or DATETIME(6), when creating the table. Otherwise, MySQL truncates fractional digits at insert time.
MICROSECOND() returns NULL if expr is NULL or cannot be parsed as a valid time or datetime. Passing an invalid calendar date like '2026-02-30 10:00:00.123456' also returns NULL.
Frequently Asked Questions
Does MICROSECOND() work on DATE columns without a time part?
No, DATE values do not contain time or fractional seconds. Passing a DATE-only string like '2026-05-10' can fail time parsing and return NULL, while a DATE column evaluates to 0 when promoted to DATETIME.
Why did MICROSECOND('10:15:30.25') return 250000 instead of 25?
MySQL treats .25 as 0.25 seconds, which equals 250,000 microseconds. Always divide or format carefully if your application expects milliseconds instead of microseconds.
Can MICROSECOND() accept negative TIME values?
Yes. For a negative duration such as '-00:01:05.123000', MICROSECOND() still returns the positive integer 123000.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.