The MICROSECOND() function in MySQL is used to extract the microsecond part of a given time or datetime value. It returns the microsecond portion as an integer value, representing the number of microseconds (i.e., millionths of a second) in the specified time.
Syntax:
MICROSECOND(time)
time: ATIME,DATETIME, orTIMESTAMPexpression from which you want to extract the microseconds.
Example Usage:
-
Using
MICROSECOND()with aDATETIMEvalue:SELECT MICROSECOND('2024-12-23 14:30:45.123456');This will return
123456as the microsecond part of the givenDATETIME. -
Using
MICROSECOND()with aTIMEvalue:SELECT MICROSECOND('14:30:45.123456');This will return
123456, which is the microsecond part of the givenTIME. -
Extracting the microsecond from the current timestamp:
SELECT MICROSECOND(NOW());This will return the microsecond part of the current timestamp.
Notes:
- If the input does not contain a microsecond part (for example, if it's just
TIMEorDATETIMEwithout fractional seconds),MICROSECOND()will return0. - The function operates on the fractional part of a time, which includes the microsecond component if present.
No comments:
Post a Comment