MySQL - Calculate the net time difference between two date-times while excluding breaks?

Posted by John M on Stack Overflow See other posts from Stack Overflow or by John M
Published on 2010-03-23T18:28:07Z Indexed on 2010/03/23 18:33 UTC
Read the original article Hit count: 219

Filed under:
|

In a MySQL query I am using the timediff/time_to_sec functions to calculate the total minutes between two date-times.

For example:

2010-03-23 10:00:00
-
2010-03-23 08:00:00
= 120 minutes

What I would like to do is exclude any breaks that occur during the selected time range.

For example:

2010-03-23 10:00:00
-
2010-03-23 08:00:00
-
(break 08:55:00 to 09:10:00)
= 105 minutes

Is there a good method to do this without resorting to a long list of nested IF statements?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about time