Productivity Guru is a great resource on YouTube with his video on Templater and Date formats. I have been playing with Date formats since I watched his video earlier today

For your christmas example I get PTO.159S

Try the one further down below.

Or, the better one:

<%+* let edate = moment("12-24", "MM-DD"); let from = moment().startOf('day'); edate.diff(from, "days") >= 0 ? tR += edate.diff(from, "days") : tR += edate.add(1, "year").diff(from, "days") %>

which takes into consideration that Christmas this year might already have passed.

Or even:

<!-- Days until any "MM-DD" date this year/next year with "TODAY" -->
<%+* let edate = moment("12-24", "MM-DD"); let from = moment().startOf('day'); edate.diff(from, "days") >= 0 ? edate.diff(from, "days") == 0 ? tR += "It’s today!" : tR += edate.diff(from, "days") : tR += edate.add(1, "year").diff(from, "days") %>

Will do once I get my windows sync with iCloud working again. Actually I believe now it is totally corrupted and I can only use my iPad or phone to work with Obsidian. Then all the templates do not work because of it being the private beta version.

1 Like

It’s been super helpful to incorporate these into my regular reviews & my workflow. Any idea how I could list the weekly notes in each month’s note?
I know how to list the daily notes for that month, and the monthly notes for that year, but not the weeks. I’m doing weekly notes in the format GGGG-[W]WW, yielding e.g. 2021-W38

In case anyone else needs to do this, @shabegom suggested this answer which works great:

const currentMonthDates = new Array(moment(tp.file.title,'YYYY-MM').endOf('month').week() - moment(tp.file.title, 'YYYY-MM').startOf('month').week() + 1).fill(null).map((x, i) => moment(tp.file.title,'YYYY-MM').startOf('month').add(i, 'weeks').format("- ![[gggg-[W]ww[]]]")).join('\r\n') %>
<%* tR +=  currentMonthDates %>

Hi all,

Is it possible to create a time-blocking list of 15 minute increments, something like;

e.g. if the current time is 08:51, I might want to start my time blocking at 09:00

- <% tp.date.now("HH:mm", +x min) %>
- <% tp.date.now("HH:mm", +15 min) %>
- <% tp.date.now("HH:mm", +30 min) %>
- <% tp.date.now("HH:mm", +45 min) %>
- <% tp.date.now("HH:mm", +60 min) %>

one would just need to insert the adjustment time x, and it would be a nice little focus prompt alongside a pomodoro timer.

thanks!

Hey @dryice! I’ve actually once written two complete moment.js addons for rounding date/time and generating date/time intervals. These are a little more complicated and not so easy to add to Obsidian, so here are two simpler solutions, maybe one of these fits your bill:

Very simple (and ugly) solution without Javascript:

- <% moment().add(15-(moment().minute()%15),'minutes').startOf('minute').format('HH:mm') %>
- <% moment().add(15-(moment().minute()%15),'minutes').startOf('minute').add(15, 'minutes').format('HH:mm') %>
- <% moment().add(15-(moment().minute()%15),'minutes').startOf('minute').add(30, 'minutes').format('HH:mm') %>

Simple solution using Javascript:

<%*
let start = moment().add(15-(moment().minute()%15),'minutes').startOf('minute');
tR += "- " + start.format('HH:mm') + "  \n";
// moment.js dates are mutable, so always only add 15 mins!
tR += "- " + start.add(15, 'minutes').format('HH:mm') + "  \n";
tR += "- " + start.add(15, 'minutes').format('HH:mm') + "  \n";
%>

It is assumed that both of these are saved as a Templater template in the template folder, and inserted upon request (Alt+E).

Result (for both) should be (at 19:58:17):

  • 20:00
  • 20:15
  • 20:30
1 Like

Many thanks, both solutions work perfectly, and yes, the second is nice and tidy! :ok_hand:
Have a lovely weekend!

1 Like

Hello @Moonbase59 – I’m reading through this read and this is a wealth of knowledge. You’re a true tinkerer. I’m running into trouble and wanted to see if you saw something I was doing simply wrong or if you knew of a smart way to achieve this.

I’m looking to dynamically link all the months in a quarter, depending on the quarter. As such, I was planning on writing something like:

 <%* if (tp.date.quarter() == "1") { %>
- 2021-1
- 2021-2
- etc
<%* } %>

However, I’m getting Templater Error: Template parsing error, aborting. tp.date.quarter is not a function.

I’ve also tried to use tp.date.now().quarter(), but get a similar error.

Am I doing something wrong? I thought that Templater exposed the entire Moment object and methods?

Thanks in advance for your help!

@ScottKillen has a terrific “if-else if” example using the Templater plugin that may be able to help you. use-the-templater-plugin-to-create-repeating-tasks-on-future-or-past-daily-notes

1 Like

@musa Try moment().format("Q")

Dynamic Commands
Why would:

<%+ tp.file.last_modified_date("YYYY-MM-DD HH:mm:ss") %>

not work in frontmatter but in the body of a note it works perfectly well?

Did you ever figure out how to get the months in the quarter to work?