How to calculate amount of time in dataview query

“2023-01-24 Exile Habits” is a file of its own with the two dataview fields:

Start: 10:00
End: 12:00

I would like that the column “Duration” showing “2 hours” or something alike.

This works. Might be other ways:

start: 10h00m 
end: 12h00m
tag: atestnote

end - start AS duration
from #atestnote

This is a good catch, thank you.

The only thing is that I have no real control on the values of the field start and end, because they are automatically created by the Full Calender plugin. Thus, I need a way to calculate duration with “10:00” and “12:00”.

1 Like

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

1 Like

Many thanks!!! This solves my problem.