MySQL time() function; In this tutorial, we would love to share with you MySQL time() functions with the help of its definition, syntax, parameter, and examples.
MySQL time() Function
Definition:- Time() function is the inbuilt function of MySQL, which is used to select the time part from the given DateTime or time.
Note:- If you can pass wrong DateTime or time and NULL value in this function, returns “00:00:00”.
Syntax
TIME(DateTime/Time)
Parameters of time function
DateTime/Time:- It is a required. To extract the time from the datetime or time.
Example 1 Of Time() Function
Let’s take the first example, In this example, we will pass the DateTime value in time() function and it will extract the time part from the DateTime value:
SELECT TIME("2020-01-04 10:21:15");
The output of the above query is the following:
10:21:15
Example 2 of time() function
Let’s take the first example, In this example, we will pass the NULL value in time() function and it will extract the time part from the NULL value:
SELECT TIME(NULL);
The output of the above query is the following:
TIME(NULL)
Example 3 – Fractional Seconds
Here we will take the third example, In this third example, we will select/extract time fractional time part of the given DateTime value.
SELECT TIME('2020-01-04 11:14:12.123456');
The output of the above query is the following:
11:14:12.123456