I’m trying to get the duration function to display zero durations but it doesn’t display anything. = dur(15m) → 15 minutes = dur(0m) → # nothing, what I want here is “0 minutes”
Things I have tried
I thought I would be able to use something like default, but it doesn’t work. I can’t find another function that could possibly work.
= default(dur(0m), "0 minutes") → # nothing, I was expecting “0 minutes” = default(dur(1m), "0 minutes") → 1 minute
So clearly not returning “null” when the resulting duration is zero.
Then I thought I should try the “durationformat” function. I thought if I can ask it to format less than a minute into minutes it might give me “0 minutes” but I’m getting these lovely errors.
for =durationformat(dur(1s), "m 'minutes' ")
“Dataview (inline field ‘durationformat(dur(1s), “m ‘minutes’”)’)”: Error
and for = durationformat(dur("1s"), "m minutes")
"Dataview (for inline query ‘[object Object]’): Unrecognized function name ‘durationformat’ "
Then I thought I would check the settings and see I could change the null return to actually be “null” and I did in Settings → Dataview → Render As Null → “enter value”, but this just proved one thing = dur(0m) is not returning “null”
I need something, that display a value, when either, no value or null value passed to it. Is there a way to do this?
I’m not entirely following what your actual use case is, but I found that while dur("0 m") indeed returns an empty string, the expression dur("0 m").minutes returns the number 0. This can also be utilised in stuff like the choice() functions, or similar.
Furthermore, I don’t get the same error messages you get, but then again your post is slightly botched by the forum post formatting rules.
Bonus tip: How to present code properly in a forum post
If you want to showcase either markdown, or code blocks, or dataview queries properly in a forum post, be sure to add one line before and one life after what you want to present with four backticks, ````. This will ensure that any other backticks (like in code blocks or queries) is properly shown.
I’m comparing dates and getting the duration is days. I don’t want to see blanks in the results. That about boils it down. I want consistency in the delta results, I want to see “1 day”, “10 days” or “0 days” not a blank cell.
I have this query
```dataview
TABLE a-date AS Applied, dur(a-date - p-date) AS Delta
FROM "/"
WHERE (p-date AND a-date) AND dur(a-date - p-date).days <= 10
SORT Delta ASC
LIMIT 5
```
Currently I get these like this results, and it just looks like data is missing.
I have to think about what I’m seeing to really make sense of it, instead of quickly getting what I need at a glance.
File (3)
Applied
Delta
Job 1
January 26
Job 2
January 26
3 days
Job 3
January 26
1 week, 3 days
That’s all that is behind this question.
But I can live with your suggestion of using the unit method for the duration.
TABLE a-date AS Applied, dur(a-date - p-date).days AS "Delta (days)"
File (3)
Applied
Delta (days)
Job 1
January 26
0
Job 2
January 26
3
Job 3
January 26
10
So, yeah, this works too, but I really wanted the units displayed. I guess I can close this now.