Hi @Moonbase59 thanks for all your info, this clarifies a lot. I hope you don’t mind if I have some follow-up questions. If this gets too much off topic I hope I can contact you via pm.
It’s a pity that the info cannot be updated after e.g. changes to a note. I thought that the Templater: Replace templates in the active file function would be able to do this. Do you know what this function does?
Do you know of a way how to have an updating ‘last modified’ header in the note?
It replaces templater code within the currently open file, so you don’t have to load an external template. Like, you type <% tp.file.last_modified_date() %>, then press Alt/Opt+R and you’ll get the file’s last modified date and time.
I never had much use for this (except for testing), since the templater code is replaced with its result and thus gone afterwards.
Nope. If you find one, let me know Then again, Obsidian’s File Explorer pane shows the last modified date if you hover the mouse over a file, and it could possibly be retrieved “live” using the Dataview plugin.
We must remember, after all, that Obsidian is a system to create/handle plain Markdown text notes and not a “live”, variable- or event-driven system like a website could be.
Thanks for this discovery! This should be in the documentation already. I was looking for this since the day dynamic commands were released but in my attempts to try this, it never worked, I think I tried the asterisk before the plus and then tried the documentation and gave up. This could be so useful especially since we can call external APIs using fetch inside the template and process it as we like with JS.
This is a little longer, but it will check if it’s already past the date for this year, and show the difference in days until the same date next year!
This is ideal for recurring events like Christmas, Birthdays, Anniversaries, etc.
To make things simple, I use JS to set a variable at the beginning. This allows editing just one place instead of many.
<!-- Days until any "MM-DD" date this year/next year -->
<%+* let edate = moment("12-24", "MM-DD"); let from = moment().startOf('day'); edate.diff(from, "days") >= 0 ? tR += edate.diff(from, "days") : tR += edate.add(1, "year").diff(from, "days") %>
Days until …, plus “It’s Today!”
Same as above, but will display “It’s today!” instead of a plain old zero if we happen to be on the date.
<!-- Days until any "MM-DD" date this year/next year with "TODAY" -->
<%+* let edate = moment("12-24", "MM-DD"); let from = moment().startOf('day'); edate.diff(from, "days") >= 0 ? edate.diff(from, "days") == 0 ? tR += "It’s today!" : tR += edate.diff(from, "days") : tR += edate.add(1, "year").diff(from, "days") %>
Enjoy! (And never again worry about “days to Christmas” being -2!)