The TIME() function in MySQL is used to extract the time part from a given date or datetime expression. It returns a time value in the format HH:MM:SS.
Syntax:
TIME(expression)
- expression: This can be a date, datetime, or timestamp value.
Example Usage:
-
Extracting the time from a datetime value:
SELECT TIME('2024-12-23 14:30:45');Result:
14:30:45 -
Using with columns in a table: If you have a
datetimeortimestampcolumn, you can extract just the time part:SELECT TIME(order_datetime) FROM orders; -
Using with the current time: You can also use
TIME()to get the current time:SELECT TIME(NOW());
Notes:
- The
TIME()function returns a value in the formatHH:MM:SS. - If the input is a string that cannot be converted to a valid time, it returns
NULL.
Let me know if you'd like further clarification!
No comments:
Post a Comment