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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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: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.