How do I fetch date from title using Templater Plugin?

Hi,

When I click a date on the Calendar, a new note with its title as that day’s date is generated.

eg: 2021-08-15

Now, I have created a Daily Review Template using “Templater”, which says " today is "today’s date " & Two Links “Yesterday” & “Tomorrow” which creates note for Yesterday & Tomorrow.

14Aug 0116PM 0

but whenever I create a template, it is showing today’s date in the template instead of that day.

I want my template to fetch the title of the note, consider as the date, and create two links as Yesterday & Tomorrow. How do I do this :disappointed_relieved:

My Template

## MD's Daily

<< [⏪ Yesterday](<% tp.date.yesterday("YYYY-MM-DD") %>) || 
[Tomorrow ⏩](<% tp.date.tomorrow("YYYY-MM-DD") %>) >>

#### <% tp.date.now("dddd, Do MMMM YYYY") %> Note

I tried

<% tp.file.title %>

but how to consider this as today’s date so that I could generate the “Yesterday” & “Tomorrow” Link ?

1 Like

This is what I have in my template:

<< [[<% moment(tp.file.title,'YYYY-MM-DD').add(-1,'days').format("YYYY-MM-DD") %>|⏪ Yesterday(<% moment(tp.file.title,'YYYY-MM-DD').add(-1,'days').format("YYYY-MM-DD") %>)]] | [[<% moment(tp.file.title,'YYYY-MM-DD').format("YYYY") %>-W<% moment(tp.file.title, "YYYY-MM-DD").isoWeek() %>|Week: <% moment(tp.file.title, "YYYY-MM-DD").isoWeek() %>]] | [[<% moment(tp.file.title,'YYYY-MM-DD').add(1,'days').format("YYYY-MM-DD") %>|Tomorrow(<% moment(tp.file.title,'YYYY-MM-DD').add(1,'days').format("YYYY-MM-DD") %>) ⏩]] >>

It uses the moment javascript library, which is either included with Obsidian or tp, so it should just work. Documentation can be found:

4 Likes

Thank You :blush:. It does work when I create a black note & use it as a template.

But, when I included it in “periodic notes plugin” & use it from Calender it does not render ‘tp’ or 'moments’:disappointed_relieved:


I don’t think the “Templater plugin” works with “Periodic Notes Plugin”

Anyway, for now I am using it without periodic notes plugin, I would appreciate it if you would share “Weekly” & “Monthly Template” ! :pray:

See also: Could we have something like Dataview’s `this.file.day`? · Issue #328 · SilentVoid13/Templater · GitHub

2 Likes

Updated template, this template can be used as a template for Calendar, creating “Today”, and in an empy note, which has a title “YYYY-MM-DD”. It moves the file in place (if needed), and renames it, which “fixes” the calendar getting confused:

---
tags: journal
date: {{date:YYYY-MM-DD}}
up: 
rating: 
---
<< [[<% moment(tp.file.title,'YYYY-MM-DD').add(-1,'days').format("YYYY-MM-DD") %>|⏪ Yesterday(<% moment(tp.file.title,'YYYY-MM-DD').add(-1,'days').format("YYYY-MM-DD") %>)]] | [[<% moment(tp.file.title,'YYYY-MM-DD').format("YYYY") %>-W<% moment(tp.file.title, "YYYY-MM-DD").week() %>|Week: <% moment(tp.file.title, "YYYY-MM-DD").week() %>]] | [[<% moment(tp.file.title,'YYYY-MM-DD').add(1,'days').format("YYYY-MM-DD") %>|Tomorrow(<% moment(tp.file.title,'YYYY-MM-DD').add(1,'days').format("YYYY-MM-DD") %>) ⏩]] >>
<% tp.file.move("/Journal/" + tp.file.title) -%>
<% tp.file.rename(tp.file.title) -%>

# <% moment(tp.file.title,'YYYY-MM-DD').format("dddd") %>, <% tp.file.title %>

<% tp.web.daily_quote() %>

## Today
Import yesterday's remaining todos!<%tp.file.cursor(0)%>
## Today I Learned

My Weekly and Monthly templates are still a “work in progress”, they just show a title, haven’t figured out yet what would be usefull.

FYI, weeknumbers are surprisingly complicated, for myself I partly follow the US numbering, but with the week starting on a Monday, for more reading, see: momentjs - week numbers

5 Likes

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