I have a gps php application and a database table with route travel data:
START ROUTE(timeA) END ROUTE(timeB) DURATION LENGHT (KM)
'2018-08-11 00:09:33', '2018-08-11 01:06:36', '57:3 ', '53.29'
'2018-08-11 01:17:06', '2018-08-11 01:25:58', '8:52 ', '7.11'
'2018-08-11 01:49:24', '2018-08-11 01:49:44', '20 ', '0.05'
'2018-08-11 02:05:49', '2018-08-11 02:25:39', '19:50 ', '15.30'
'2018-08-11 02:35:20', '2018-08-11 03:54:24', '1:19:4 ', '84.62'
I need to calculate sum of each days between an date interval and hours interval. I have made a query for that:
$quu = ("SELECT SEC_TO_TIME(SUM(UNIX_TIMESTAMP(timeB) - UNIX_TIMESTAMP(timeA))) AS period, SUM(lenght) AS lenght FROM apm_travel_sheet WHERE timeA BETWEEN '$zistart' AND '$ziend' AND imei='$imei' ORDER BY timeA ASC");
$ress = mysql_query($quu) or die(mysql_error());
while($row = mysql_fetch_array($ress)) {
$period = $row['period'];
$lenght = round($row['lenght'], 2);
It work great, but if the route start before search interval hours and end in interval, query do not include minutes from interval. Example: I want to run query for this interval: start: 2018-08-01 22:00 end: 2018-08-02 06:00
If in DB I have a route that start at 2018-08-01 21:46 and finish at 2018-08-02 22:40 in result it not shown because start is not in interval. I need to modify query to show that 40 minutes because is in selected interval and I do not have any idea...
Thank you for help!