Dataview plugin snippet showcase

for the record… over on Discord @arminta solved this problem…
TABLE (file.mtime.hour + ":" + file.mtime.minute) as Time
That did the trick nicely. Many thanks @arminta

1 Like

The SORT function in Dataview seems to sort words starting with a capital letter ahead of those in lowercase, e.g. I get this list:
ability to pay
If the sorting was purely alphabetical “Apple” should be at the end of this list.
Do others observe this behaviour?

Excuse me if this has already been answered elsewhere, but I could not find an answer. I would like to extract a year from a full date in a dataview query. The YAML front matter has a ‘Finished’ date (YYYY-MM-DD), and I would like the displayed result in the Field in the table to show the YYYY. Is there a function for this? Also is it possible to run a query to find all the files where the Finished date is YYYY (not full date)?

You can use this snippet to show all files named after the folder they are in:

where contains(replace(file.path, + ".md", ""),

There are some edge cases, but this should show you the file in the path Resources/Computers/

You can use the .year method on the date to extract only that part :slight_smile:

table Finished.year as Year

You can do the second thing using this:

where Finished.year = 2021

That’s terrific, thanks so much! Works a treat. The bit that I am still stuck on is a bigger issue of how to decide what to put into YAML Frontmatter and what to keep outside it. It seems that if something is in front matter it cannot get a back link (e.g. from author page). So I guess that any metadata one wants to be able to back link to from another note should stay out of front matter…?

1 Like

Yes, yaml wikilinks aren’t real links. Aside from returning then in a dataview table, there isn’t a way to click them and go to that link.

links: [[Note]]

table links

I don’t need to be able to click them, but I need the backlink to work from another note. For example if I put ‘Author: Some Person’ into the frontmatter, there is no Unlinked mention from the ‘Some Person’ note.

I have been developing a kludge for this that uses the Templater and Dataview plugins.

Let’s say I have a note for the author James Clear (Resources/People/Clear,

first-name: James
last-name: Clear
aliases: ['James Clear']

And I also have a note for his book Atomic Habits (Resources/Books/Atomic with the following YAML front matter:

author: 'Clear, James'

I can use Templater and Dataview to add a dynamically updated list of James Clear’s books to the note on James Clear. The template for such a list, Templates\List of Books by this, is as follows:

## Books

list from "Resources/Books"
where author = "<% tp.file.title %>"

After I use Templater to insert the template into Resources/People/Clear,, the source looks like this:

first-name: James
last-name: Clear
aliases: ['James Clear']

## Books

list from "Resources/Books"
where author = "Clear, James"

And the preview renders like this:

The link to the note on Atomic Habits is clickable. Unfortunately, Obsidian’s graph does not display the relationship between the two notes.


Interesting, not even an unlinked mention.
Then yes, for now atleast, keeping those links outside the frontmatter is the only option

Apologies if this has been asked a million times.

Is it possible for the following to return the text block, instead of returning a list of pages?

list from #Task

It may not align with the way you’ve structured your tasks, but you can use Task from #Task to return all checkboxes - [ ] .
Otherwise, dataview doesn’t currently allow you to embed the content of a note

It’s probably simple but I could not manage it:
Outgoing links from all notes with a specific #tag

Any ideas?

Does this work:

list from outgoing([[Note]]) and #tag

But there are many notes with that specific tag. So I cannot mention one specific [[Note]]. I think I was not clear…

let me try again: #emotion is a tag that is included in multiple notes. These notes have outgoing links. I am trying to make a table that lists the note names tagged with #emotion in one column and list the outgoing links (from each note tagged #emotion) in a second column. :man_shrugging:

Hi all. I’m trying to create a way to list notes whose date field is greater than a duration, where the duration is another field value.

My YAML looks like this:

    name: "my project"
    review_schedule: 1 week
    last_reviewed: 2021-04-01

With my desired query looking something like this

TABLE WHERE date(today) - project.last_reviewed >= dur( project.review_schedule )

It works if I harcode dur( 1 week ) but doesn’t seem to convert project.review_schedule to the equivalent.

Any suggestions?

What is the syntax to search for a specific word inside a file from the entire vault?
This one is not working

list "foo bar"
from ""
sort asc

Ahh I see. That would require a general file.links property which is not currently accessible.
This is the same as the difference between asking for all notes with the tag #Tag, and fetching the tags from all notes with the tag #Tag. With this example, we can do both because we have the file.tags property. But file.links is not available


You can’t query the content of a file at the moment. Something like file.content would be amazingly powerful, though!

Interesting question! I played around with it, and it seems that if you have a yaml field with a number and a time duration - just like you have there 1 week - then you don’t have to tell dataview that it is a duration!
So your query should work like this:

WHERE date(today) - project.last_reviewed >= project.review_schedule