[Templater] Date in frontmatter not working

What I’m trying to do

First time using Templater! So, probably just don’t understand how exactly it is working!!

---
startDate: <% tp.date.weekday("DD/MM/YYYY", 1) %>
endDate: <% tp.date.weekday("DD/MM/YYYY", 7) %>
---
<% tp.date.weekday("DD/MM/YYYY", 1) %>
<% tp.date.weekday("DD/MM/YYYY", 7) %>

<% await tp.file.rename("Week " + tp.date.now("ww") + " (" + tp.date.weekday("DD. MM.", 1) + " - " + tp.date.weekday("DD. MM. YYYY", 7) + ") _new")%>

Template “code” under the YAML/frontmatter is showing correctly - Monday and Sunday of the current week. But the date inside the YAML/frontmatter is showing wrong …

image

Things I have tried

Read about dates at tp.date - Templater and Moment.js | Docs, but nothing helped. As I mentioned - this is my first time using and playing with Templater, so I am still learning, but this confused me. What is the reason behind these dates in YAML/frontmatter?

Thanks! Marko :nerd_face:

I think the issue isn’t with Templater, but with the date format Obsidian is expecting in the frontmatter. Obsidian defaults to ISO dates, which is YYYY-MM-DD.

To verify if my assertion is correct, try the following…

  1. create a date in your frontmatter using the calendar picker in the pull-down in the startDate property.
  2. Look at the frontmatter/YAML in source mode and look at the format of the date created by Obsidian.
1 Like

OMG :exploding_head: … just that I started reading your answer, I knew you were right, and I’m ashamed that I didn’t think about it!

Anyway - working, and thanks!

Cheers, Marko :nerd_face:

1 Like