MySQL Time Function

MySQL Time Function is useful to extract the Time part from the given DateTime. In this study, we show you how to use this method to extract the time value from the given expression with an example, and the syntax is

TIME(Time or DateTime or expression);

MySQL Time function Example

Here, we are using this method to extract the Time value from the expression and different Datetime expressions. Also, read about the MySQL TIME_FORMAT function.

SELECT TIME('10:12:34');

SELECT TIME('2016-05-19 11:14:34');

SELECT TIME('2016-05-19 16:14:39');
Time Function Example 1

We are extracting the Time value from the current datetime returned by the MySQL NOW, MySQL UTC_TIME function, and MySQL UTC_TIMESTAMP function.

SELECT NOW(), TIME(NOW());

SELECT UTC_TIME(), TIME(UTC_TIME());

SELECT UTC_TIMESTAMP(), TIME(UTC_TIMESTAMP());
Time Example 2

In this Date method example, we are trying to return the Time value from the String DateTime format.

SELECT NOW(), TIME(NOW() + 10);

SELECT NOW(), TIME(NOW() + 10);

SELECT UTC_TIMESTAMP(), TIME(UTC_TIMESTAMP()+10);
TIME Function Example 3

Here, we are trying to return the value from different DateTime formats. Within the last MySQL statement, we used the zeros.

SELECT TIME('2016-05-19 11:14:34.111234');

SELECT TIME('11:14:74.111234');

SELECT TIME('00:00:00');
MySQL Time Function 4

Example

Using the Time function on table data. Here, we are returning the output from the Hire Date column.

TIP: Please refer to the MySQL HOUR and MySQL MINUTE functions from the list of available MySQL Date functions.

SELECT EmpID,
       FirstName,
       LastName,
       Occupation,
       YearlyIncome,
       Sales,
       HireDate,
       TIME(HireDate)
 FROM customer;
MySQL Time Function 5