I'm using Tasker and am trying to set up a profile that would track how many hours I spend at work. I've managed to set up the tracking part, which inserts the data in a Google Spreadsheet like this:
Arrived 2017-03-11 10:15
Left 2017-03-11 12:40
Arrived 2017-03-11 13:00
Left 2017-03-11 15:50
Arrived 2017-03-11 17:30
Left 2017-03-11 21:20
What I'm wondering is: How can I add the final piece – counting the hours at my office, provided that I leave it several times per day. So for this example, the result is 9:05:00.
I guess what I'm looking for is a loop, that would go trough each date, calculate differences, and add all of them into a cell.
How would I go about doing this?
Best Answer
I made a simple version of your problem you can play around with: Make a copy of the sheet
There are basically two things to do:
1. Get the duration for each visit
For that I added a Column with an arrayforumla (so we don’t have to copy it in every row) that basically looks if we are in a “Leave” row and if so, gives us the time difference between the leave and the arrival before that.
(expanded for better readability
(Note: Your table needs to be well formated for that, meaning Leave and Arrival should always alternate)
Now you already got the duration for each visit.
Aggregate for each day
To make this simpler, lets add a Col to our sheet, that figures out the day without time for each row. Like this:
The important part is the
INT(B2:B)
which converts yourdatetime
to adate
Now I would recommend to create another sheet and automatically generate a day overview there, by simply putting a
query
in A1.That’s it! Here is the sheet.