Calculating Time Difference from Time Fields in MySQL
You have a MySQL database with a 'time' field that stores event occurrence times in minutes:seconds format. To determine the total time elapsed between two events, it becomes necessary to convert these values into a decimal format.
To accomplish this, you can utilize the TIMESTAMPDIFF function provided by MySQL:
<code class="sql">TIMESTAMPDIFF(MINUTE, T0.created, T0.modified)</code>
This function will provide you with the total elapsed time in minutes. To express it as a decimal, you can simply divide the result by 60. For instance, in the example provided, the result would be:
<code class="sql">60 minutes / 6.67 minutes = 8.97</code>
This gives you the precise decimal representation of the time difference between the two events. Refer to the MySQL documentation for additional information on the TIMESTAMPDIFF function: https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_timestampdiff.
The above is the detailed content of How to Calculate Time Difference in Decimal Format from MySQL Time Fields?. For more information, please follow other related articles on the PHP Chinese website!