I am struggling with a table that show me a start time and an end time of a machine status, and I would like to sum the hours but only considering day by day.
As an example:
ID STATUS START_TIME END_TIME
01 OPERATIVE 12/01/2020 08:00:00 14/01/2020 08:00:00
02 OPERATIVE 11/01/2020 05:00:00 13/01/2020 02:00:00
My expected result would give me a table showing that in 11/01/2020
, the machine number 2 worked from 05:00:00
to 23:59:59
, so it would be 19h
. Machine number two did not work at all.
In 12/01/2020
, machine number one worked from 08:00:00
til 23:59:59
- 16h
and machine number two worked the whole day: 24h
, so it would give me 24h + 16h in this day = 40h
.
And so it goes, giving me as part of the final table:
DAY WORKING_HOURS
11/01/2020 19H
12/01/2020 40H
So, what would you guys recommend me to do? How can I solve it?
Thanks in advance,