# Calculate duration between start and end time

Beginning from a note that track my working hours like this

• 2023-11-09 08:55-17:55
• 2023-11-10 09:01-17:04
• 2023-11-11 08:52-12:00
• 2023-11-12 08:52-12:00
• 2023-11-13 08:52-12:00
• 2023-11-14 08:52-12:00
• 2023-11-15 08:52-12:00

I want to calculate how many hours I work per day, and if it’s possible how many hours per week.

Can you help me with this?

thanks

Will there only be one note, or will you repeat this pattern in multiple notes and need to combine those into that weekly hour calculation?

The gist of the idea to solve something like this using the dataview plugin would be to use regex to extract the date, the start-time and the end-time, and then map that into proper `DateTime` objects which can be used for calculation. Then one would build/map a new table of that into the date and the duration of work hours for that day, group this on the days and sum up the daily work. This could then in the same, or another subquery (if using dataviewjs), be used to group on the week and redo the sums for the week.

It’ll take some work, but it’s doable with a little bit of fiddling around (if you know a little bit of coding).

2 Likes

I’m working on something similar. I’ve got something like this:
START::
some notes
END::

When I query for START it returns a list, likewise for END. If I could find a way to smush the two lists together into a table it would be as simple as `TABLE sum(END-START)`, but I can’t find a way to do that. I can index into the list but I can’t find a way to iterate through it so I can only use a literal value for the index. This is the point I’m stuck at now.

TABLE END[0]-START[0]
where file.name = this.file.name

You should start a new thread for your request @Supetorus , and please add some examples on which time format you’re using, and how many start/time combos you expect in any given note.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.