itew
December 21, 2024, 3:40pm
1
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
FsOver2
December 21, 2024, 7:27pm
3
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]
FsOver2
December 21, 2024, 8:13pm
4
@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`
%>
itew
December 25, 2024, 1:10pm
5
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?
FsOver2
December 25, 2024, 2:32pm
6
Could you please provide some more detail of your setup?
Just to verify, you’re saying this exact template used to work?
Did you try replacing your existing template with the one I suggested earlier?
What are the names of your plugins?
What does your file structure look like for your notes?
Did you update anything in Obsidian or install a new plugin around the time you noticed the dates stopped displaying correctly?