Automatically update last modified date in note

In case someone is still interested in realising the automatic update of last modified date in the current note like the post here, here is my solution using the Dateview plugin.

  1. Install Dateview plugin in Community plugins. Enable it.
  2. Enable the JavaScripts Queries as well as the Inline JavaScripts Queries in the plugin’s settings.
  3. Now you just need to put this line wherever you want to have the modified date displayed:
    `$= dv.current().file.mtime`
    

For demonstration, here is how I use this trick:

> [!info]- Metadata
> - Created::  `$= dv.current().file.ctime`
> - Updated::  `$= dv.current().file.mtime`

Hope it helps!

13 Likes

Nice, the only thing is that this does not work on the frontmatter section :c

3 Likes

That’s great. How would you modify it for format the last modified output as: YYYY-MM-DD?

Is there any trick that could put this in the frontmatter?

5 Likes

file.cday
file.mday
https://blacksmithgu.github.io/obsidian-dataview/annotation/metadata-pages/

How can I use it inside markdown?

---
alias: "paper note"
last-reviewed: `$= dv.current().file.mtime`
topics:
---

Doesn’t work for me :confused:

2 Likes

Trying to figure this one our as well - Did you manage to figure it out?

I am trying to put it in the frontmatter of my Templater template

1 Like

This is really easy to do with a plugin. I just made a quick one to do it, which is now in the plugin store.

Super simple, it will automatically update a YAML/frontmatter property every time a file is modified.

9 Likes

What or how anything is different in yours from Update time on edit plugin?

1 Like

This part:

This plugin will read the ctime and mtime from the file system. If file change from an external source, the header keys will be updated.

The one I made only updates the time when you edit the note inside Obsidian, rather than if the file modified time changes for whatever reason (example copying files to a new computer).

Different approach depending what you want.

3 Likes

I actually disabled that plugin (which had been updated twice in succession and I found something detrimental) a few days ago when I batch-changed my YAML and was looking for an alternative solution. I’ll try yours.

Cheers

1 Like

Sure, give it a go. It’s very simple, this is the whole code:

this.registerEvent(this.app.vault.on('modify', (file) => {
  if (file instanceof TFile) {
    this.app.fileManager.processFrontMatter(file, (frontmatter) => {
      frontmatter[property] = moment().format(format)
    })
  }
}))

I only wrote it as an example for this thread, but it does what it needs to.

2 Likes

“yyyy-MM-dd” format is not honoured. Day is exchanged for Tue (it’s Tuesday where I’m at).

Also, same as the other plugin (now I remember why I disabled it), double-quotes my frontmatter keys (tags field). How come?

Yes it is, you just didn’t use MomentJS format like it mentions.

Nothing is double quoted at my end. If you’re using 1.4.x just remember that it’s not ready yet and they’re still fixing bugs.

1 Like

YYYY-MM-DD indeed works.
It’s only one tag actually. I’ll figure it out.

Cheers

Hi, I’ve tried implementing this but I am getting the following error message. Anybody know how to solve this?

I have opened a new fault in Obsidian and now the times do work. Anybody knows what the issue might be?

Excellent, this is what I was looking for. System mtime is changed each time my Dropbox synchronizes files between different machines, so it’s frequently not reflecting actual time, while your plugin will update the modification time only when I actually edit the file.

1 Like

Glad to help :+1: I have no idea why the other two plugins which update a modified field use the file system time.

2 Likes

Truth be told, when running normal or regex replacements from other programs (Notepadqq, for instance), I see the field updated – but Obsidian was left open.

Slightly more concerning is this. Disabling these plugins seems to make this confounding issue stop.

  • Wonder what is causing the interference here.

Now I use the manual way of Save [Contrl+S] with Linter (Lint current file with ‘lint on save’), which updates date modified.