Dataview plugin snippet showcase

Another question: Is there a syntax to shorten the file.ctime output (ie: to just DD-MM)? I guess there is no default attribute such as file.date?

A few ways you could do this, last one is what I think you’re looking for.

  1. Extract the properties you care about from file.ctime using .day and .month into two different columns

So this:

table file.ctime.day, file.ctime.month

Will give you this:

  1. Make a list of those two properties to have them in one column:

So this:

table list(file.ctime.day,file.ctime.month) as creation

Will give you this:

image

  1. Use string concatenation to combine the relevant properties into one cell:

So this:

table file.ctime.day + "-" + file.ctime.month as creation

Will give you this:

image

2 Likes

What an awesome plugin. Thanks for developing it.

I would like to achieve something really simple to print only mtime under the title of a note.

I tried

list file.mtime

But then I got a list of all notes and their mtime. It also shows the title of the note which is not necessary.

Is this is possible?

Hey Jan! I didn’t develop dataview, I’m just a big fan :grinning_face_with_smiling_eyes:

You can use this hacky way of doing it:

table rows.file.mtime as Modified
where file.name = this.file.name
group by file.name

Will give you this table:

3 Likes

:smile: thanks for this.
It’s a bit much for what I want (space wise) so I continue my quest to find a way to add mtime as a single text string. If you run into something like that somewhere in the future please let me know!

2 Likes

I created an issue on GitHub because I thought dataview wouldn’t display all files in my inbox. Turned out it was a feature:

## Did you know …

… that dataview will only list non-empty files?

I had played around with my new Obsidian URI desktop shortcut to create new datetime-stamped note in your Inbox and created lots of empty test files and I use a “Inbox Table-of-Content” note that uses dataview but didn’t show all files:

table file.ctime, file.mtime
from "+Inbox"
where file.name != "+Inbox TOC"
sort file.mtime descending

So now we know! :slight_smile:


EDIT: Turns out that after putting a single character into one of the empty files, it gets listed, but when removing it again (thus emptying the file) it still gets listed. Odd.

EDIT 2: Dataview 0.2.10 didn’t catch all events. This has been fixed in 0.2.13 and I could verify today (with 0.2.14) that the problem has gone.

This also means I was assuming the “empty file feature” (which isn’t true). Thanks @blacksmithgu for fixing it!

FWIW, you can do:

table rows.file.mtime as Modified where file.name = this.file.name group by file.name

No need for the line breaks.

But, dataviews will only work using triple-backtick code fences, so you still need the opening ```dataview (and the closing triple-backticks).

Does any dataview wizard know if you can dynamically subtract dates between fields? I’m trying to create a table of my projects and how long they’ve taken. I’ve got “date-started” and “date-finished” YAML variables for my projects, but I can’t tell if you can create another column that dynamically tells you the duration of the project based on those two fields. I tried defining another variable “length” and subtracting date-started from date-finished, but that doesn’t seem to work.

table status, date-finished, date-started
from ""
where status
sort status desc

Sample note YAML:

---
status: complete
date-started: 2020-06-28
date-finished: 2020-08-29
length: date-finished - date-started
---
1 Like

Hey Janek. You should be able to use a computed field like so:

table (a - b) as NewField

In your example:

table status, date-finished, date-started, (date-finished - date-started) as Length
from ""
where status
sort status desc
3 Likes

4 posts were merged into an existing topic: Dataview, strange display

@SkepticMystic I’m just getting started with Obsidian and came across your amazing plugin - great work. I am interested in a roadmap feature you have mentioned “Hierarchical view”. Not sure what you have in mind but I thought I would describe a need I have in case its relevant. I would like to extract and visualise the hierarchy embedded in a group of notes - specifically each note is an entity (place, person, thing, etc) with a [[link]] to another entity inside it (in my case it is a simple parent-child relationship). I would like to be able to extract all of this and visualise it in a mind map view (similar to the Mind Map plugin). Is that compatible with your thinking?

Hey Simon :slight_smile:
This isn’t my plugin, I’m just a fan!
Regarding your question, I think what you have in mind could work! Checkout @arminta’s reply here, perhaps she can also give you some pointers.

1 Like

@blacksmithgu posted this on GitHub in reply to my question regarding displaying modified time in a note:

This is now possible via inline queries; just put an inline code block in your file:

`= this.file.mtime`

Great!

3 Likes

Also works for other things like …

Last modified: `= this.file.mtime`
Last modified date: `= this.file.mday`
Tags: `= this.file.tags`
Aliases: `= this.file.aliases`

Really great! :grinning:

Now we’ll only have to wait for …

  • date/time string formatting
  • date/time strings being localized into the currently set Obsidian language, not the system language

See Is it possible to specify a format when displaying a date? · Issue #120 · blacksmithgu/obsidian-dataview · GitHub

4 Likes

@SkepticMystic
I watched your video today (thanks for that!). Re your section on “lists”. I could not get any of them to work and I don’t know if perhaps the last couple of updates broke it or if I’m doing something wrong. Presumably I should be able to write list fieldInYaml from "Folder" and get results, right?

With country: UK in my yaml, and list country from "Film/Film Titles" I get no results.

1 Like

Apparently we can’t sort by computed fields?

My note names will always start with a 4 digit year in some folders (ie. 2019.Something) and dataview allows me to correctly extract/display this year from file.name, but it won’t allow me to sort based on it:

```dataview
table regexreplace(file.name, "(?<=\d{4})(.*$)", "") AS Year
FROM "Unsorted/Projects" 
WHERE landmark = "yes"
SORT Year desc
```

The table is there, File/Year columns and results, but sorting it by Year won’t do anything be it ASC/DESC, I can pretty much use sort with any undefined string, same result.

Here are two three other nice ones:

Assuming you use a location: in your front matter (as I do for places of interest)

---
name: Berlin, Weltzeituhr
location: [52.52134162768218, 13.41327381161729]
---

you can create dataview inline external links to Google Maps and Street View like this:

`= elink("https://www.google.com/maps/search/?api=1&query=" + this.location[0] + "," + this.location[1], "On Google Maps")`

Google Maps Search Link created "live" from front matter data, using Dataview!

`= elink("https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=" + this.location[0] + "," + this.location[1], "On Street View")`

Google Street View Link created "live" from front matter data, using Dataview!

`= elink("https://www.google.com/maps/dir/?api=1&dir_action=navigate&destination=" + this.location[0] + "," + this.location[1], "Google Navigation")`

Google Navigation Link created "live" from front matter data, using Dataview!

These even work in PDFs generated from the note.

6 Likes

wow, that’s crazy!

Hee hee, yes! And useful.

Locate my daughter on the (Obsidian Leaflet) map, have a popup come up, click on the “Route” link, hop over to the map opening in the browser, click “Send to smartphone” … and start driving!

You guessed it—I have a location: front matter entry for People, too. :nerd_face:

4 Likes

Hi friends, I’ve made some posts showing some examples of how I use dataview:

Hope you find them helpful.

17 Likes