MySQL TIME() Function
The TIME()
function in MySQL extracts the time portion from a datetime or time value. This is useful for separating the time element from a date and time value, allowing you to work with just the time component.
TIME(): Definition and Usage
TIME()
is frequently used to isolate the time part of a timestamp for various time-related operations or to format data for display. If the input is not a valid datetime or time value, it returns "00:00:00". If the input is NULL
, it returns NULL
.
Syntax
Syntax
TIME(expression)
Parameter Values
Parameter | Description |
---|---|
expression |
The time or datetime value from which you want to extract the time. This is required. |
Examples
Extracting Time from a TIME Value
This example extracts the time part from a time expression.
Syntax
SELECT TIME("19:30:10");
Output
19:30:10
Extracting Time from a DATETIME Value
Extracting the time portion from a datetime value.
Syntax
SELECT TIME("2017-08-15 19:30:10");
Output
19:30:10
Extracting Time with Microseconds
Handling microseconds in the datetime value.
Syntax
SELECT TIME("2017-08-15 19:30:10.000001");
Output
19:30:10.000001
Handling a NULL Value
Showing the result when the input is NULL.
Syntax
SELECT TIME(NULL);
Output
NULL