Change duration format to hour

I have a time tracker to track how many hours I spent to do an activity.

After one of my activity reaches 24 hours. it displayed using day. I want it to display them as hours (like steam hours played).

I currently use this dataview query that I discovered on obsidian forum

TABLE WITHOUT ID sum( filter(flat(rows.SE), (r) => typeof(r) = "duration" )) as "Total Time Spent" 
FROM #Daily 
GROUP BY true

Things I tried

  • changing “duration” to “duration.hours”

Try this …

TABLE WITHOUT ID 
round(sum(filter(flat(rows.SE), (r) => typeof(r) = "duration")) / dur(1 hour), 2) as "Total Time Spent (h)"
FROM #Daily 
GROUP BY true

… I’m not behind the computer to properly test it :frowning_face:

Cheers, Marko :nerd_face:

=dur(450 minutes) = 7 hours, 30 minutes
=dur(450 minutes).hour = 7.5

unfortunately this doesnt work, and this error comes out

Why do you divide by a duration? What is your current query which gives this error?

What do you get with this variation:

```dataview 
TABLE WITHOUT ID sum( filter(flat(rows.SE), (r) => typeof(r) = "duration" )).hour as "Total Time Spent" 
FROM #Daily 
GROUP BY true
```
1 Like

Maybe if we see the source, it would be easier. As with “duration”, I’m unsure what/where/how you’re getting it.

You can read more about it here: Literals - Dataview

And how to format duration, here: Functions - Dataview

Cheers, Marko :nerd_face:

  1. Sorry I dont quite understand your first question,

  2. the query that gives the error above is this one

TABLE WITHOUT ID 
round(sum(filter(flat(rows.SE), (r) => typeof(r) = "duration")) / dur(1 hour), 2) as "Total Time Spent (h)"
FROM #Daily 
GROUP BY true
  1. Using your variation I get this

which is cool (thx)
is there a way to put the word “hours” behind the numbers?

I use properties on my daily notes, like this

I found what Im looking for, thx for all the help :grinning:

Just change the .hour as "Total... part to .hour + " hours" as "Total....

1 Like