@a_wue Possible you haven’t updated Dataview for a while? The dateformat function is rather new. (Luxon comes with Dataview, no worries.)
(Community plugins don’t auto-update. You have to manually “Check for updates” in Settings, and perform the update by clicking “Update all” or “Update” on selected plugins.)
Have you toughs about integrating standard DATAVIEW syntax for creation of the tables, and JS only for making variable that will be used in the table?
What I’m struggling now is that I have DATAVIEW queries, but I want to add just one field that needs to be calculated by Javascript.
Also is there any way we can add javascript into file like is the Obsidian.css, and just call it? I really don’t like to have bunch of script in dataview script.
Also is there any way we can add javascript into file like is the Obsidian.css, and just call it?
You’ll find an answer to that in this thread, but unfortunately it doesn’t work on Android or iOS. The dataview script where you are importing your common code will blow up on mobile.
I am very grateful for your snippet that gives me a table with every page in my vault. Because I want to clean the vault from unused /old files, it is very useful for me.
Maybe it’s the most stupid question – but why do I get an error message, when I rename the file name from “Inbox” to anything else, like “Inhaltsverzeichnis”. It says: Dataview: Query returned 0 results.
This is the code-snippet I use:
table dateformat(file.mtime, "dd.MM.yyyy") as "bearbeitet" where file.name != this.file.name and contains(file.path, this.file.folder) sort file.mtime descending
This might have to do with caching. After renaming -Inbox TOC to Inhaltsverzeichnis, close and re-open the TOC note once, and the Dataview content should update:
Btw, I have the code slightly refined in the meantime:
table
dateformat(file.ctime, this.dateformat) as Created,
dateformat(file.mtime, this.dateformat) as "Last modified"
where file.name != this.file.name and contains(file.folder, this.file.folder)
sort file.mtime descending
and use a YAML frontmatter variable for the dateformat:
Yes, after closing and re-opening, everything worked out fine, thanks!
Just in case, if it doesn’t bother you: Do you happen to know, how to add a column with a moment().fromNow(); function – to show for how long a file has not been worked on? Unfortunately, I have not any programming background…
table
dateformat(file.mtime, "dd.MM.yyyy") as "bearbeitet"
moment().fromNow(); as "unbearbeitet seit"
where file.name != this.file.name and contains(file.path, this.file.folder) sort file.mtime descending
In Dataview, you could add a new column “Untouched for” like so:
(date(now) - file.mtime) as "Untouched"
This will output rather long “human-readable” strings like “2 months, 1 weeks, 2 days, 11 hours, 2 minutes, 15 seconds, 107 ms”. If instead you wanted to show only the number of days untouched, it might require using DataviewJS.
Thanks for all of your posts! They have been helpful in getting started. I have a beginner question, do I need to require Luxon library at some point in Obsidian? I know Moment is already installed and I can not seem to locate how to add additional JS libraries to use in code such as dataviewjs? Thanks for any guidance.
Don
As you say, moment.js is already available, and Luxon is available in ```dataviewjs code blocks (Dataview brings it in, but not globally, use luxon.something).
Supergenial! Works like a charm - thanks a lot!
Now I enjoy my new TOC a lot. Way back, in Notion, I used a similar way to sort notes by date of modification. It just helps me to keep an eye on rarely used files.
wow thank you so much for this, it’s exactly what I’m looking for. Though I’m not quite sure how to implement. I’ve got dataview installed (have been using it for leaflet maps).
Can I have this function just look at a folder instead of using a searchterm? Or at least how do I identify a note as being ‘People’ so that it will show up on the birthday list? Also, where do I put the dataviewjs code?
Thank you so much for this script! It’s making it much easier for me to set up my hotkeys and keeping them on the side as I figure out my workflow.
Is there an easy way to omit any of the commands not assigned with any hotkeys? (get rid of all the rows containing “-”?)
I don’t know any javascript. Managed to figure out some basics like swapping out Mac commands and removing the command ID column, but struggling to find a solution for the above.
Thanks for your kind words, appreciate it! You can use the “Commands sorted by assigned hotkey” part alone, it will only show the commands with hotkeys, not the complete command list. Or put the two parts in two notes
Hey everyone! I just wanted to share that my plugin CustomJS is now available on the community store. It allows you to write and reuse javascript across Obsidian, and works on desktop and mobile. It pairs great with Dataview, which is my primary use case. See the Advanced Example section of the README for how I’m using it with dataview to manage my tasks.