How to calculate amount of time in dataview query

Part of the issue is that a duration is the time span between two dates, and “10:00” and “12:00” aren’t dates, they’re just strings. However, since we don’t really care which date this time happens on, we can trick the system:

duration: `= date("2023-01-01T12:00") - date("2023-01-01T10:00")`

Which produces the wanted: “2 hours”

In other words, given the start and end, you should be able to insert the following into your query: (date("2023-01-01T" + end) - date("2023-01-01T" + start)) as duration

Or possibly a little nicer, use a FLATTEN construct like:

FLATTEN (date("2023-01-01T" + end) - date("2023-01-01T" + start)) as duration

And then insert duration into the table column

4 Likes