Templater "Created" and "Modified" dates suddenly started having problems

I’ve been using Templater for several months with no issues at all, but I’ve recently run into a weird problem. My use of Templater is probably about as basic as you can get, (I use it for Date Created and Date Modified) but…

Templater is not updating the “Modified Date” on notes any more. It remains static even after editing the note, moving to a new one and then back to the one I edited.

If I try running the template (ALT-R) while in the note, the Date Created and Date Modified Templater code both get replaced with the text: “NaN”
creation date: NaN
modification date: NaN

Oddly, I’ve never run into that issue before, but I also only discovered the Templater ALT-R feature while trying to do troubleshooting and re-reading the docs.

Looking back at some of my backups, a backslash has appeared on every note and the every template. I don’t remember if this was some older Templater syntax or if something odd has happened to add it. As I mentioned, Templater stamping of Date Created and Date Modified has been working perfectly for probably close to a year, if not longer.
Here’s an example of what I see in pretty much every note and template file now with that backslash added:

**Created:** <%+ tp.file.creation\_date() %>
**Modified:** <%+ tp.file.last\_modified\_date() %>

Things I have tried

I’ve replaced my Date Created and Date Modified code with a copy/paste directly from the Templater documentation, so they are now currently:

creation date: <% tp.file.creation_date() %>
modification date: <% tp.file.last_modified_date("dddd Do MMMM YYYY HH:mm:ss") %>

That stamps the note correctly, but doesn’t update it after an edit.

If I add a + after the opening <% so I have <%+ (which is what I’ve been using for several months with no issues) it seems to work, but only sometimes… Sometimes it works, and sometimes it just displays the Templater code as text when you switch the view on the note from Edit to Read.

creation date: <%+ tp.file.creation_date() %>
modification date: <%+ tp.file.last_modified_date("dddd Do MMMM YYYY HH:mm:ss") %>

Oddly, if I add the backslash back in, it seems to have no impact either way…

  • I’ve uninstalled and re-installed Templater. (I also confirmed the folder for the plugin was deleted after I uninstalled Templater.)
  • I confirmed the core Templates plugin was still disabled.
  • I confirmed the core Daily Note plugin was still disabled.

What I’m trying to do

What I’m trying to do is have Templater do what it’s being doing beautifully for a loooong time. :slight_smile:

  1. Show the date the Note was created.
  2. Show the date the Note was modified.
1 Like

The NaN issue using dynamic commands started in November with an update. "NaN" (from dynamic command) spreading through my vault · Issue #910 · SilentVoid13/Templater · GitHub

I use dataview for modification date now:

updated: `=dateformat(this.file.mtime, "DDDD, HH:mm")`

which works in both Live preview and Reading modes, but it can’t be in the frontmatter.

1 Like

That works perfectly, thank you! :pray:

I also noted in the discussion you linked to that the use of the dynamic Templater code may get deprecated at some point, so it was a good exercise (for me) to make the switch now.

FWIW, I have this at the start of every note. (It’s a combination of an Admonition callout and the info I had that showed date created, modified and file path - now updated to use Dataview.)

collapse: open
**Created**: `=dateformat(this.file.ctime, "DDDD, HH:mm")`
**Modified**: `=dateformat(this.file.mtime, "DDDD, HH:mm")`
**Location**: `=this.file.path`

Which results in something like this. (This is what I see when I’m editing the template file for notes related to apps.)

And just for comparison: the file path on the note I have for Affinity Designer.
Screenshot 2022-12-30 212219

1 Like


The Admonition looks good.

Yeah, <% tp.file.creation_date("") %> still works fine in Templater (as the creation date never changes), but after the dynamic commands ( <%+ ) stopped working, I thought: how much do I really switch to Reading mode to look at those anyway? Dataview for the win!

1 Like

Hi guys,
I´m quite new to obsidian so apologize my question.
I had the same issue wiht the modified date and tried now your solution using Dataview, the coding

updated: `=dateformat(this.file.mtime, "DDDD, HH:mm")`

doesn´t work.
I have other dataview codes in my files that are working fine, so I´m wondering if you have any idea on what the issue could be.

Have you turned on inline queries for dataview? I think they’re disabled by default.

yes it is

I use for instance

not done
due before <% tp.date.now("YYYY-MM-DD") %>

for my daily notes and it works great

Could it be because of a different date format I´m generally using?

Those are not dataview queries, rather tasks query.

Please go into Settings > dataview, and check for online queries

1 Like

Could you make a screenshot maybe of how it looks in edit view in your vault so I could compare the exact syntax?
As mentioned, I´m true freshman

As holroy said, this isn’t a dataview query.

My Dataview settings screen looks the same as yours. What does

`= this.file.name`

produce for you? It should return the file name.

It returns the file name…
I found my mistake, thank you so much guys.
I thought I need to embed the query into “```”.
Could you please explain to me why for the above code I need to embed this while for the simple dataview query I don´t?

To your original issue, try pasting

`= dateformat(this.file.mtime, "DDDD, HH:mm")` 

into a note again. What does it return? How doesn’t it work? If ‘this.file.name’ works, I’m at a loss why ‘dateformat…’ wouldn’t.

So, many plugins utilise the code block to enclose their query or input. This applies to tasks, dataview, admonition, and many others. A code block is a block of lines surrounded by three (or more) backticks, ```, (or tildes, ~~~).

These blocks are also used for presenting code from various programming languages, and I think why they are used for plugins is their ability to contain many lines of text, and a built-in feature for tagging the block with a name which is easy to get at and used by the markdown processor.

However, in this thread we’re not talking about just a query, but an inline query. This is a special case made to be used in line with text of a paragraph.

This requires a different syntax, and the base syntax is yet again inspired by the one used from presenting code within the paragraph, which is single backticks around the phrase, like `…`.

And finally to identify that code as an inline dataview query, that code phrase has to start with the equal sign, =, so it becomes: `=…`.

1 Like

It works fine now, I just used the inline query wrong

Thank you so much for the explanation.
I indeed need to learn still a lot

Is there any update by now how to make it function again in the frontmatter?

If you are referring to the Templater NaN issue, I would check their GitHub page for any updates on the issue.