Wednesday, October 29, 2014

Calculating Elapsed Time with MySQL

These MySQL functions will calculate the difference between two date/time stamps.
SEC_TO_TIME(TIMESTAMPDIFF(SECOND,max(startDateTime),now()))
as "Time Delta"

The inner function, TIMESTAMPDIFF, calculates the difference between the current date/time and the date/time field named, startDateTime, in seconds. The outer function, SEC_TO_TIME, converts seconds into hours, minutes, and seconds.