Wrong date stated in template

Hey guys, I have this piece of code inside one of my templates and it doesn’t seem to give the correct date for some reason. Can somebody help me get it working? thanks.

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

<< [[Purpose/Routine/Daily/<%fileDate = moment(tp.file.title, 'DD-dddd').subtract(1, 'd').format('YYYY/MM-MMMM') %>/<%fileDate = moment(tp.file.title, 'DD-dddd').subtract(1, 'd').format('DD-dddd') %>|Yesterday]] | [[Purpose/Routine/Daily/<% fileDate = moment(tp.file.title, 'DD-dddd').add(1, 'd').format('YYYY/MM-MMMM') %>/<% fileDate = moment(tp.file.title, 'DD-dddd').add(1, 'd').format('DD-dddd') %>|Tomorrow]] >>

What I’m trying to do

Things I have tried

The issue might be how you’re naming your notes. Just to confirm, is this an example of your note name? I’m basing this off your script output.

Purpose/Routine/Daily/2024/12-December/19-Thursday.md

The script expects to use just your file name and can’t use the path as part of the date. Let us know you’re note name so we can correctly identify how to approach your issue.

[Edit: clarified the script uses just the name not the path]
[Edit: spelling]

@itew , assuming the file path name…

Purpose/Routine/Daily/2024/12-December/19-Thursday.md

I think this template will do what you’re looking for…

<%*
const fileDateObj = moment(tp.file.path(true),'[Purpose/Routine/Daily/]YYYY/MM-MMMM/DD-dddd[.md]');
const headerStr    = fileDateObj.format("dddd, MMMM DD, YYYY");
const yesterdayStr = fileDateObj.subtract(1, 'd').format("YYYY/MM-MMMM/DD-dddd");
const tomorrowStr  = fileDateObj.add(2, 'd').format("YYYY/MM-MMMM/DD-dddd");
tR += `# ${headerStr}\n\n`
tR += `<< [[Purpose/Routine/Daily/${yesterdayStr}|Yesterday]] | [[Purpose/Routine/Daily/${tomorrowStr}|Tomorrow]] >>\n\n`
%>

Sorry, I use a template extension for my daily notes. I just create a new note from one of the templates but recently the notes have all had the same date. What do you suppose I do?

Could you please provide some more detail of your setup?

  1. Just to verify, you’re saying this exact template used to work?
  2. Did you try replacing your existing template with the one I suggested earlier?
  3. What are the names of your plugins?
  4. What does your file structure look like for your notes?
  5. Did you update anything in Obsidian or install a new plugin around the time you noticed the dates stopped displaying correctly?