DataviewJS calculate time between 2 timestamps for multiple entries

What I’m trying to do

Hey, im trying to create a dataviewjs table that shows me my work sessions, these are saved like this via a 3rd party programm:

Intention:: test
Category:: General
Startdate:: 2023-07-15T13:02:28Z
Enddate:: 2023-07-15T15:02:28Z

I want to display the Intention, Category, Startdate, Enddate as well as the Duration between these 2.

Later on i might also want to display the duration as Hours, Minutes, but currently it doesn’t work for more then 1 entry. If you have tips on this I would highly appreciate these as well.

Things I have tried

I already have a working solution for one of these worksession entries but once i have 2, like this:

Intention:: test
Category:: General
Startdate:: 2023-07-15T13:02:28Z
Enddate:: 2023-07-15T15:02:28Z

Intention:: test2
Category:: General2
Startdate:: 2023-07-16T14:02:28Z
Enddate:: 2023-07-16T14:02:28Z

My solution shows me “NaN”

const dailies = dv.pages('"Daily Journal/15.07.2023"')
	.mutate(p => p.duration = calculateDuration(p["Startdate"], p["Enddate"]))


dv.table(["Startdate", "Enddate", "Duration"], 
		 dailies.map(p => [p["Startdate"], p["Enddate"], p.duration]))

function calculateDuration(start, end) {
	var timestamp1 = new Date(start);
	var timestamp2 = new Date(end);
	return timestamp2-timestamp1
}

Any idea on how i could fix this / another solution that would work ?

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