Date pull from current date, but lock that date

Things I have tried

I am using a dataview query to pull pages created and updated today. This goes in my daily note for that day. This is what the current code looks like:

LIST WHERE file.cday = date(today)

What I’m trying to do

Not surprisingly that updates every daily note with those pages for the current date. What I want it to do is to hold the date. For example, the daily note for 2022-07-14 would show only notes created on that date. If I were to look back at 2022-07-13 I would want it show only pages created or modified on the 13th. Is there a way to do this without manually adjusting the date every day?

Thanks for the clear explanation! You have a couple options. Per the dataview docs, if your daily notes have titles that include the date “of form yyyy-mm-dd or yyyymmdd” or you have a frontmatter or inline-field with the date then the daily note will have an implicit field called file.day. So inside that daily note you could say LIST WHERE file.cday = this.file.day to compare everything to that daily note’s day rather than “today”.

Thanks for this. The only problem I run into with this is sometimes the creation date of a daily note precedes the actual date. For example, I may link a task to a day in the future or make a note for a meeting in the future.

1 Like

Good point! Luckily, file.day and file.cday can be totally different dates. Does the title of the daily note have the date in it? (in yyyy-mm-dd or yyyymmdd format)? If so, what does this test query inside such a future note LIST this.file.day FROM "theActualTitleOfThisFutureDailyNote" give you? I would hope it would print the title of the note as a link and then the date corresponding to the note. Does that then work as a replacement for date(today)? Or am I missing something?

I tried that, but it returned no results. I’m not sure if I did something wrong or not.

For reference, I used:

LIST this.file.day FROM "2022-07-19"

That was the future note that I was testing on.

Here is mine from my Daily Note. This doesn’t solve your problem of creating a daily note before the actual day. Then again, my use case wouldn’t really allow that.

### Notes Modified / Created Today
```dataview
TABLE file.mtime as "Modified"
WHERE file.mday = this.file.day
SORT file.mtime DESC
```
### Notes Modified / Created in last 7 days
```dataview
TABLE file.mtime as "Modified", file.ctime as "Created"
WHERE file.mtime >= (this.file.ctime - dur(7 d))
SORT file.ctime DESC
```
1 Like

EDIT: Aha I figured it out! Sorry that I forgot this in my prior post. If you are using a filename in your FROM, it needs to be the full path of the file within the vault, not just the name. So for example my daily notes live inside a folder called “days” inside the root of my vault, so inside my “2022-07-19” note, my query needed to be LIST this.file.day FROM "days/2022-07-19". Hopefully you should get a result now!

Huh! I am surprised and confused! It worked for me. Are we on the same version of dataview? I’ll check mine for updates (Settings → Community Plugins → button that says “Check for Updates” then “Update”, then close and re-open Obsidian if there were any updates that got installed).
Thanks for sharing your file title! Since the title is just a date, maybe for a query inside that file you can use date(this.file.name). Have not tested this one yet, will edit this post after I check for updates and test.

EDIT: date(this.file.name) should also work from inside that file. Here’s a table I just made to test, both columns looked the same to me. Note you’ll have to replace the FROM with whatever the path to your note is.

TABLE
this.file.day AS "day",
date(this.file.name) AS "name"
FROM "days/2022-07-19"

Good luck!

Out of curiosity, do you know if this can work if one names a file “22-07-15” (and not “2022-07-15”)

I suspect this.file.day will not work in that case but you might be able to use the title and just add a "20" + in front of it, or something like that.
EDIT: This worked for me:

LIST file.cday
WHERE file.cday = date("20" + this.file.name)

holy crud - you rock !

1 Like

You can easily automate this through a daily note template. :tada:

Steps

  • Create a daily note template somewhere in your Obsidian vault. Check sample templates below.
  • Enable Daily Notes (Settings (Options) > Core Plugins > Daily Notes).
  • Set template location for Daily Note core plugin (Settings (Core Plugins) > Daily notes > Template file location = Path/to/your/template/here.

Basic Template


## Tasks 🏁
- [ ]
- [ ]
- [ ]

## Notepad 📝



## Journal 📙



## Notes ✍️
<font color="#888">Notes created or modified today.</font>
```dataview
LIST FROM "" WHERE file.cday = date({{title}}) OR file.mday = date({{title}})
`` `

Remove the intentional space added to end back-ticks (`` `) from the dataview block before saving to your template. I don’t know how to escape back-ticks here. :thinking:

I assume that you’re using default note title i.e. YYYY-MM-DD. If not then replace date({{title}}) with date({{date:YYYY-MM-DD}}) and another date({{title}}) with date({{time:YYYY-MM-DD}}).

Templater Plugin

This template assumes you’re using Templater plugin.

<% tp.web.random_picture("900x300", "tree,landscape,water,mountain") %>

> [!INFO] Today's Calendar
> https://calendar.google.com/calendar/r/day/<%tp.date.now("YYYY/M/D") %>

## Tasks 🏁
- [ ]
- [ ]
- [ ]

## Notepad 📝




## Journal 📙




## Notes ✍️
<font color="#888">Notes created or modified today.</font>
```dataview
LIST FROM "" WHERE file.cday = date(<%tp.date.now("YYYY/MM/DD") %>) OR file.mday = date(<%tp.date.now("YYYY/MM/DD") %>)
`` `

Again, pls remove the intentional space added to end back-ticks (`` `) from the dataview block before saving to your template. I don’t know how to escape back-ticks here. :thinking:

Here is the sample output in my Obsidian.


Hope it helps! :innocent:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.