Home >Database >Mysql Tutorial >How to Calculate Time Difference in Minutes from MySQL Time Fields?
Determining Time Difference in Minutes from MySQL Time Fields
You have encountered the need to calculate the time difference between two events recorded as 'time' fields in your MySQL database. These fields do not follow the conventional HH:MM format but represent the time remaining in an event. For instance, a value of 5:45 signifies an occurrence with 5 minutes and 45 seconds remaining.
Solution:
To achieve your desired result, you can leverage the TIMESTAMPDIFF() function, which calculates the difference between two timestamps. Employing this function with your specific case, you can determine the time elapsed between the two events as follows:
<code class="sql">TIMESTAMPDIFF(MINUTE, T0.created, T0.modified)</code>
In this expression:
The result will be the time difference expressed in minutes. To obtain the decimal representation, you can simply divide the difference by 60.
The above is the detailed content of How to Calculate Time Difference in Minutes from MySQL Time Fields?. For more information, please follow other related articles on the PHP Chinese website!