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)"