Nick Milo’s weekly newsletter mentioned using a base template when creating a new note that contains related and created properties. He properly shows <% tp.file.creation_date() %>, but it made me realize that sometimes I use tp.file.creation_date, but elsewhere I use tp.date.now.
However, the latter will not generate the correct date when it’s created on a different day). So I reviewed my usage across my existing periodic note templates, and need to make them consistent and correct.
Be careful how you create dates using templates with the Templater plugin. This is critical when creating new periodic notes in Obsidian.
Templater dates
There is a subtle difference between two ways to create dates—tp.date() uses the current date, whereas tp.file.creation_date() uses the file date.
Let’s consider what would happen if today were 2024-01-19 (Fri) and I clicked on a future day like tomorrow (2024-01-20) in the calendar pane of the inspector. It would create a new Daily Note with a Markdown document with the name 2024-01-20.md under Calendar/Notes/2024/01 folder. However, if you click on Get Info for this file in Finder, it shows the Created date as January 19, 2024 at 2:13 PM, and the Modified date is the same.
YAML Properties
Looking at the YAML front matter, the created property appears like this:
---
up:
- '[[2024-W03]]`
related:
created: "2023/01/2024-01-20"
tags:
- note/periodic/daily
---
Note Title
However, the generated note title like this, which creates a Markdown header 1 (without the hash format prefix):
# Daily Note - Fri, Jan 19.
Back/Forward Links
Also, currently my existing template shows the previous/next days (or maybe back/forward) like this:
<< [[2024-01-18|Yesterday]] | [[2024-01-20|Tomorrow]] >>
Although the created property is correct, my note title and the previous/next days are wrong!
They were using tp.date.yesterday() and tp.date.tomorrow(), which seemed to make sense when I first created my daily template. That worked fine when creating this daily on that same day, like I do with my Daily Startup shortcut that runs automatically every morning at 6 am.
But when I create a Daily Note for some other day in the past or future, this approach generates an incorrect date since the current date is being used instead of the target date for the new file being created.
Solution
For that to work properly, I must use tp.file.creation_date() instead of tp.date.now().
So I should use the following for the note title:
<% tp.file.creation_date("DDD MMM D")%>
so I get “Sat Jan 20”, not “Fri Jan 19”.
Likewise, I need to be using this snippet in the template to generate the proper previous and next days around the new daily note.
<% tp.date.now("YYYY-MM-DD", -1, tp.file.title, "YYYY-MM-DD")%>
<% tp.date.now("YYYY-MM-DD", 1, tp.file.title, "YYYY-MM-DD")%>
So that might appear something like this:
[[2024-01-19]] < Today > [[2024-01-21]]
or maybe:
<< [[2024-01-19]] | [[2024-01-21]] >>
If I wanted to see these displayed in relative terms, I could use this variation:
<< [[2024-01-19]]|Yesterday | [[2024-01-21]]|Tomorrow >>
These MUST be based on the name of the periodic note file itself, regardless of when it’s created (for back/forward links), instead of the current date.
Daily Reviews
This is especially important when creating my plan for tomorrow during my review at the end of each day since I will want to create a new daily note for tomorrow which I would initialize with stuff that I need or want to do tomorrow. Although it would be created on today for tomorrow, it has to be generated so it uses tomorrow’s date (not today).
Perhaps, during my Daily Startup when creating the Daily Note, I should also create one for the following date as well. However, that would still require that the template being used generates the dates properly.
Weekly Reviews
The same approach needs to be followed for other periodic notes: weekly, monthly, quarterly, and yearly. In the weekly case, calendar week numbers get especially tricky, since the standard week starts on Sunday, whereas ISO week number begins on Monday. I know I have to account for this in my Shortcuts that create my weekly notes.
I prefer to use Monday to start my weeks, so the weekends appear at the end. Therefore, you need to use the correct week number if generating weekly notes such as 2024-W03 for Jan 15–21 (starting on Mon).
Summary
Remember, there are subtle differences that are signficant:
- Current date:
<% tp.date.now() %>
- File date:
<% tp.file.creation_date() %>
In the meantime, I’m going through my periodic templates to get them cleaned up, consistent, and correct.
Like this:
Like Loading...