"Modified" in metadata is not working

I use the following on the top of the note:

---
created:  <% tp.file.creation_date("dddd YYYY-MM-DD HH:mm") %>
modified: <% tp.file.last_modified_date("dddd YYYY-MM-DD HH:mm:ss") %>
---

The ‘modified’ time in the preview never changed. Even though I edit the file today, it still shows the old time. Did I miss anything?

Created Thursday 2023-02-02 10:53

Modified Thursday 2023-02-02 10:53:36

Check this discussion, I think it looks at a similar issue Templater "Created" and "Modified" dates suddenly started having problems - #18 by DimiK

When using a template to create a file, it’s using the values which was correct at the time when it inserted the template. It’s by default not dynamically updated later on.

You insert the template, and it’s done. It’s a static insert.

One execption to this rule when using Templater is that you can use <%+ tp.file.last_modified_date %>, which will update when you switch to reading view. However, this will then not be accessible for queries from. (Or to be more precise: it’ll carry over the template it seems and list the modification time of that file instead… ) Another caveat with this approach, is that caching will affect when it’s updated.

As also discussed in the other thread, it’s a possibility to move these fields out of the frontmatter, and try using dataview queries. This will work to some extent, and they’ll update more often than the Templater counter part. But then again, they’re also prone for cache issues. However, they’re most likely your best bet to get to show these dates.

So maybe something like the following would suit your needs:

> [!info]- File stats
> Created: `= dateformat(this.file.mtime, "DDDD, HH:mm:ss") `
> Last modified: `= dateformat(this.file.mtime, "DDDD, HH:mm:ss")`

This creates a file stats callout, by default collapsed, but that could be changed to opened by changing the first line to > [!info]+ File stats. This now shows the created and last modified date in a locale time format with the addition of the hour, minute and seconds. Feel free to adjust time formats according to personal preferences.

This will update every now and then when dataview feels for refreshing the query. It does require for inline queries to be enabled in the dataview settings.

Try the “Update time on edit” plugin, works great for me!

I’m so fascinated by the amount of plugins written for any “random” cause. Too bad some of them are not updated after the first initial changes, which I reckon is fine for some of the plugins, and not so good for others.

Don’t see why this shouldn’t work still, though. So if it does work, it’s a much better option than using either Templater or dataview which do have the issues mentioned related to caching/refreshing.

This plugin will also cause “static” information to be held in the frontmatter, and as such the updated fields will be available for queries, if that would be wanted at a later stage.

You can use the Linter plugin for this as well. Works great for me.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.