What is a TIME() in MySQL
This function is used to extract the time part from the data provided to it, to understand it, we will consider some examples, but before proceeding to the examples, let us discuss the general syntax of using TIME():
The explanation to the syntax is very simple, just write the function and inside the function write the expression or column name from where you want to extract the time, for example, we will extract time from the expression “2021-11-15 14:25:10” using the function of TIME():
In the above command, the time is extracted from the expression which is containing both date and time, similarly, to extract the time from the present time and date, use the command:
Similarly, we can also extract time from the results of passing the NOW() function:
We can also extract time from the data of a table, for this, let us create a table of employees timesheets using the command:
We have used the “TIMESTAMP” datatype to define emp_time_rec, because in this column we want to insert date and time records, to insert data in the table, execute the command:
To display the table, run the command:
To extract the time only from the “emp_time_rec” column, use the command:
From the above output, we can see that the function TIME() extracted the time from the data of the column of “emp_time_rec” and displayed it separately.
Conclusion
MySQL is the popular RDBMS used to manage the data of the websites and applications; it supports a lot of functions that take single or multiple inputs and returns one specific output for a particular task. In this post, we have discussed the TIME() function that is used to extract the time from the given data. This function can be applied on a single input or a number of inputs of the table by using its data of the column of the table.