Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dann Berg's Daily Note Template for Obsidian. Uses Dataview & Templater plugins. Should be saved as a Markdown file in Obsidian. Read the full tour: https://dannb.org/blog/2022/obsidian-daily-note-template/
---
created: <% tp.file.creation_date() %>
---
tags:: [[+Daily Notes]]
# <% moment(tp.file.title,'YYYY-MM-DD').format("dddd, MMMM DD, YYYY") %>
<< [[<% fileDate = moment(tp.file.title, 'YYYY-MM-DD-dddd').subtract(1, 'd').format('YYYY-MM-DD-dddd') %>|Yesterday]] | [[<% fileDate = moment(tp.file.title, 'YYYY-MM-DD-dddd').add(1, 'd').format('YYYY-MM-DD-dddd') %>|Tomorrow]] >>
---
### 📅 Daily Questions
##### 🌜 Last night, after work, I...
-
##### 🙌 One thing I've excited about right now is...
-
##### 🚀 One+ thing I plan to accomplish today is...
- [ ]
##### 👎 One thing I'm struggling with today is...
-
---
# 📝 Notes
- <% tp.file.cursor() %>
---
### Notes created today
```dataview
List FROM "" WHERE file.cday = date("<%tp.date.now("YYYY-MM-DD")%>") SORT file.ctime asc
```
### Notes last touched today
```dataview
List FROM "" WHERE file.mday = date("<%tp.date.now("YYYY-MM-DD")%>") SORT file.mtime asc
```
@mapoulos
Copy link

mapoulos commented Aug 31, 2022

Thanks for sharing! I had to fix the quotation marks on ll. 31 and 36 to get this to work, and enable the "Trigger Templater on new file creation" option.

@Steellow
Copy link

Steellow commented Sep 3, 2022

Thanks! Little change I did to not show created notes on the 'modified today' section:


List FROM ""
WHERE file.mday = date("<%tp.date.now("YYYY-MM-DD")%>")
AND file.cday != date("<%tp.date.now("YYYY-MM-DD")%>")
SORT file.mtime asc

Good modification for those that want it.

I also have since modified the wording from "modified today" to "last touched today," as notes will only show in this Dataview list if the last edit date matches this date.

@cmogle
Copy link

cmogle commented Sep 6, 2022

Thanks for sharing! I had to fix the quotation marks on ll. 31 and 36 to get this to work, and enable the "Trigger Templater on new file creation" option.

Can you please clarify what you did to fix the quotation marks in ll. 31 and 36? @mapoulos

@mapoulos
Copy link

mapoulos commented Sep 6, 2022

Note the change to single quotes after tp.date.now( and before )%> here:

List FROM "" WHERE file.cday = date("<%tp.date.now('YYYY-MM-DD')%>") SORT file.ctime asc

and here

List FROM "" WHERE file.mday = date("<%tp.date.now('YYYY-MM-DD')%>") SORT file.mtime asc

@dannberg
Copy link
Author

dannberg commented Sep 7, 2022

Thanks for sharing! I had to fix the quotation marks on ll. 31 and 36 to get this to work, and enable the "Trigger Templater on new file creation" option.

I just confirmed in my Obsidian that it's working just perfectly for me with double-quotes rather than single-quotes around YYY-MM-DD. I wonder where the difference is that's causing it to break for you but work for me.

@moritzdawo
Copy link

moritzdawo commented Sep 23, 2022

I just confirmed in my Obsidian that it's working just perfectly for me with double-quotes rather than single-quotes around YYY-MM-DD. I wonder where the difference is that's causing it to break for you but work for me.

For me, it worked fine too. Only the template showed an Dataview Error, that you can fix with single quotes.

Oh and I added an <% tp.file.cursor() %> to the Notes Section, so you can start writing, when Obsidian starts with your daily note.

Thank you very much for this very great template!

@dannberg
Copy link
Author

dannberg commented Sep 23, 2022

Oh and I added an <% tp.file.cursor() %> to the Notes Section, so you can start writing, when Obsidian starts with your daily note.

That's a cool trick! I didn't even know that existed. I'm going to update the gist, and start using that myself, too.

@LovisR
Copy link

LovisR commented Sep 24, 2022

sry if thats a supid question, but does +Daily Notes do anything? or is it just the name of the file that you link all your daily notes to?

@Aron-Polner
Copy link

Aron-Polner commented Sep 27, 2022

Thanks for sharing!

To make this work you have to enable some options in Templater.

I enabled the following:

  • Automatic jump to cursor
  • Trigger Templater on new file creation

@mt190502
Copy link

mt190502 commented Oct 11, 2022

Hello. I'm trying to build my personal obsidian vault. While doing research, I came across this page and ran into a problem. With tp I get the value of the previous and next day. But when I click on it, I encounter the problem in the picture below.

image

image

@dannberg
Copy link
Author

dannberg commented Oct 11, 2022

Hello. I'm trying to build my personal obsidian vault. While doing research, I came across this page and ran into a problem. With tp I get the value of the previous and next day. But when I click on it, I encounter the problem in the picture below.

@mt190502 It looks like the Templater plugin is not firing when the new page is created. Templater should turn the <% %> tags into text, and it looks like that's not happening here. I'd review your settings in the Templater Plugin settings screen? Not 100% sure where the error is, but that's where I'd check first.

@mt190502
Copy link

mt190502 commented Oct 11, 2022

Hello. I'm trying to build my personal obsidian vault. While doing research, I came across this page and ran into a problem. With tp I get the value of the previous and next day. But when I click on it, I encounter the problem in the picture below.

It looks like the Templater plugin is not firing when the new page is created. Templater should turn the <% %> tags into text, and it looks like that's not happening here. I'd review your settings in the Templater Plugin settings screen? Not 100% sure where the error is, but that's where I'd check first.

Thank you very much for your interest. After hours of research, I solved the problem <3

@dannberg
Copy link
Author

dannberg commented Oct 11, 2022

Thank you very much for your interest. After hours of research, I solved the problem <3

Do you remember how you solved it? It might be useful to share here in case future people have the same issue.

@mt190502
Copy link

mt190502 commented Oct 11, 2022

Thank you very much for your interest. After hours of research, I solved the problem <3

Do you remember how you solved it? It might be useful to share here in case future people have the same issue.

Of course. First of all, I created the "_templates" folder in the main directory and created my templates. I selected the folder first in Settings > Templater. Then I opened the 'New File Creation Trigger' option and connected the templates to the folders as in the photo below. I ran into a few syntax errors. It worked when I fixed them too

image

@dannberg
Copy link
Author

dannberg commented Oct 26, 2022

Just updated the Yesterday/Tomorrow links to use Templater's moment() function. The old code would have broke if creating daily notes for the future.

From Lopyter on Reddit:

As they are right now, the links will be broken if you ever decide to create a day's notes before the actual date. If you want to plan the day for tomorrow, the "yesterday" link in the note will link to today's yesterday (so 2 days ago from the note's POV) and the "tomorrow" link will link to the actual note itself. Not very useful and a potential point of confusion/frustration down the line.

@123m321
Copy link

123m321 commented Oct 26, 2022

I noticed it didn't work when using another Date Format in the settings of Daily Notes (I used DD MMM, had to remove it)

@dannberg
Copy link
Author

dannberg commented Oct 26, 2022

I noticed it didn't work when using another Date Format in the settings of Daily Notes (I used DD MMM, had to remove it)

Good call. You should be able to update the Templater code to mirror the Date Format you prefer. I should add a disclaimer to the blog post. Thanks.

@Rot4n
Copy link

Rot4n commented Nov 4, 2022

For daily notes that are created in the past or future it would be better to determine the date from filename instead of current date. Here's how I did it:

For created notes:

list from "" where file.cday = date("<% moment(tp.file.title,"YYYY.MM.DD").format("YYYY-MM-DD") %>") sort file.ctime asc

And for modified notes (excluding created notes of the same day as suggested by @Steellow ):

list from ""
where
  file.mday = date("<% moment(tp.file.title,"YYYY.MM.DD").format("YYYY-MM-DD") %>")
  and 
  file.cday != date("<% moment(tp.file.title,"YYYY.MM.DD").format("YYYY-MM-DD") %>")
sort file.mtime asc

The moment(tp.file.title,"YYYY.MM.DD") part indicates that moment() should read the file title in "YYYY.MM.DD" format, which is the one I use, so adjust accordingly.
Could be useful for tomorrow/yesterday links as well.

I hope it might be useful to someone.

@Aron-Polner
Copy link

Aron-Polner commented Nov 22, 2022

Has anyone solved the "issue" when you try to jump from a Monday to a Friday?
Is there a smart way one could script so that it finds the closest existing note?

@ayyazdaniaryan
Copy link

ayyazdaniaryan commented Dec 1, 2022

@Aron-Polner oof, don't take my word for it, but you could create a user functions like previousDate() and nextDate(), pull in moment-business-days using unpkg in your custom defined functions, and then add them to the tp.date object (this object IS the moment object source).

This should enable you to use them in your template accordingly to get that wrap around. I suspect it'll slow down templater launch on first go, however. YMMV

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment