📜  mysql timediff - SQL (1)

📅  最后修改于: 2023-12-03 14:44:27.786000             🧑  作者: Mango

MySQL TIMEDIFF - SQL

MySQL TIMEDIFF is a function that calculates the time difference between two time values. The function returns the difference as a time value, which can be formatted according to your requirements.

Syntax

The syntax for the TIMEDIFF function is as follows:

TIMEDIFF(time1, time2)
  • time1 and time2 - These are the two values whose difference needs to be calculated.
Example

Let's consider an example to understand the usage of the TIMEDIFF function. Suppose we have two time values, say 08:20:30 and 10:10:00, and we want to calculate the difference between them.

SELECT TIMEDIFF('10:10:00', '08:20:30');

The above query will return the difference between the two time values in the format hh:mm:ss.

Output

The output of the above query will be as follows:

01:49:30
Conclusion

In this article, we have discussed the MySQL TIMEDIFF function and its usage with the help of an example. The function is useful when dealing with time values in MySQL, and it can be used to calculate the time difference between two time values.