I want to get total hours and minuets with the two dates base on my search query form, from 2015-11-01 06:00:00 to 2015-11-25 17:00:00, and get the hours and minuets before or after this time 06:00 - 17:00 .
Thank you for the reply…yes I tried that it works if I will not specify date range to my query.I cannot get the hour and minuets if my start_time before 06:00
This is what I am having now, and I am far away from what I want to achieve.
select time_to_sec(timediff(endtime, strtime )) / 3600 as thetime
from (
SELECT start_time as strtime,end_time as endtime
from activelogs
) as a
where time(strtime) > '06:00' AND time(endtime) <'18:00'
as you can see the last row my problem is that i cannot get the hour and minuet
2015-11-09 03:00:00 to 06:00 ->get the hour and minuet (as outside)
and the end_time 2015-11-09 10:00:00 ->from 06:00 to 10:00 get the hour and minuet.as ( inside)
and also the second row have this start_time and end_time
2015-11-09 06:00:00 and 2015-11-09 18:00:00
I want to get the hour and minuet for 06:00 to 17:00 as(inside)
and get the hour 17:00 to 18:00 as (outside)
I don’t know if this will be achieve in mysql query.
as you can see that I have 2 hours from ‘15:00:00’ to ‘17:00’ because my end_time is ‘20:00:00’ as ‘insidetime’ and also I want to get the the hours and minuet from 17:00:00 to 20:00:00 as ‘outsidetime’
Here is my sql but I could not get my desired output.I tried to get the inside first but the ouput is wrong.
SELECT Time_to_sec(Timediff(end_time, start_time)) / 3600 AS inside
FROM activelogs
WHERE Time(start_time) BETWEEN '06:00' AND '17:00'
AND start_time BETWEEN '2015-11-01 06:00:00' AND '2015-11-20 17:00:00'
I think i fixed it to show the output :), but I don’t know if this is correct
SELECT Time_to_sec(Timediff(Least(Time(end_time), '17:00:00'),
Greatest(Time(start_time), '06:00:00'))) /
3600
AS inside
FROM activelogs
WHERE start_time >= '06:00:00'
AND end_time <= '17:00:00'
if that is the correct, how can I get the outside ?like the case 1 ? do I need to create another sql query for this ?