I want the query to calculate the difference between two date time fields
to calculate total time taken
two date time fields are in same table as start_time and stop_time
- And I want to calculate total start duration and stop duration
I want the query to calculate the difference between two date time fields
to calculate total time taken
two date time fields are in same table as start_time and stop_time
You can use MySQL's UNIX_TIMESTAMP() function to convert your datetime expressions to seconds since the UNIX epoch, then taking the sum of all differences will yield the total duration in seconds:
SELECT SUM(UNIX_TIMESTAMP(stop_time) - UNIX_TIMESTAMP(start_time)) FROM my_table
See it on sqlfiddle.
Note that UNIX_TIMESTAMP() is limited to the range '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.