Is there a way to format "durations" in a Dataview table?

I use Obsidian to keep my daily journal. I created a Shortcuts automation that sends my workout data from my iPhone and creates a page in Obsidian. Then, Dataview makes a table from that data on my daily page. I have the duration set as a simple decimal (“22.4 mins”), but it gets displayed in the table as “22 minutes, 23 seconds, 1000 ms”.

Is there some sort of syntax I can use to force Dataview to display the duration more compactly? I checked this forum and the Dataview GitHub, but can’t find anything.

MY ORIGINAL ANSWER WAS RUBBISH. See below…

1 Like

If allowed, I just add an extra option using the original “22.4 mins” format:

---
duration: 22.4 mins
---

```dataview
TABLE name AS "Name", duration.minutes AS "⏱", ...
```

If your values in duration are only in minutes, then you can use the duration.minutes to get only minutes. If you use duration.hours you get the conversion of the input value (in minutes) to hours: 22.4 mins → 0.3733

2 Likes

Genius.

:clap: :clap: :clap: :clap: :clap:

Angel

Tacking into this, is it possible in the way that dateformat() allows for options to get this to show as hrs instead of hours, m or even mins instead of minutes?

Usecase: Ideally I want to display my sleep diary in the format: 8hrs 20mins

I came up with this solution to make durations more compact:

regexreplace(string(Duration), " (\w)\w+(, )?", "$1") AS Duration

3 hours, 27 minutes, 3 seconds turn into 3h27m3s

1 Like

The dot notation is what I was missing. Thanks!

This outputs the number of days based on a calculated duration.

TABLE (date(today) - creation-date).days as "Aging (days)", (target-date - date(today)).days as "Target (in days)"

Thanks to this thread, I now have a table with the duration of the files in a folder.
Is there a way to add a line to the table with the sum of all listed durations ?
(or make another Query for the total duration ?)

I tried to get some help from ChatGPT, but that didn’t work out well :joy:
I tried using things like: FLATTEN sum(duration.seconds) as Total without success.

Thanks for any suggestion!

thanks to this other thread, I know have this second query with the total duration:
(so it’s all good)

TABLE
sum(rows.duration.seconds) AS "Total"
FROM "FOLDER" 
WHERE duration !=null 
GROUP BY true

I know this is from a while ago, but I’m trying to get my apple workout data into obsidian and was wondering if you would share your Shortcuts autmoation that is doing that? Thank you!