Dataview: files created or updated the day of the daily note

What I’m trying to do

I have the attributes “created” and “updated” in the YAML frontmatter of my notes, so all of them have at least this (when I change view to Source):

---
created: 2024-01-02T20:52
updated: 2024-01-05T13:32
---

These attributes are automatically created by the Community Plugin called “Update time on edit”, and the format as you can see is yyyy-MM-dd’T’HH:mm

I also use Periodic Notes for my Daily notes. The name format for them is YYYY-MM-DD. I want to add to my daily template (I use Templater) a Dataview query that obtains files with the created or updated attribute corresponding with the day of the daily note

Things I have tried

This query, 0 results retrieved:

TABLE created as Created, updated as Modified, tags as Tags
FROM "" AND !"0. Journal" AND !"-. Templates"
WHERE contains(dateformat(file.ctime, "yyyy-MM-dd"), dateformat(this.file.day, "yyyy-MM-dd"))

The FROM is ignoring my journal and templates folder

I would want to focus on accessing to the date part of created and updated in the YAML, and not really use ctime or mtime (since I read somewhere that modified time can be updated when syncing the file and I use Dropbox for my vault), anyway I cannot get them working. I’m a total newbie in Obsidian so apologies in advance if I’m missing the elephant in the room

Hi,

I finally figured it out. Just in case someone has the same problem, I leave here the query that worked for me:

TABLE created as Created, updated as Modified, join(file.tags, " ") as Tags, join(MOC, " ") as MOC
FROM "" AND !"0. Journal" AND !"-. Templates"
WHERE contains(dateformat(created, "yyyy-MM-dd"), dateformat(this.file.day, "yyyy-MM-dd")) OR contains(dateformat(updated, "yyyy-MM-dd"), dateformat(this.file.day, "yyyy-MM-dd"))

The TABLE and FROM parts contain things as I want them so feel free to change it

I’m happy that you found a solution, and I would just like to make a few comments:

  1. contains() is mainly used to check whether one text is contained within another, or to check whether a list has an element (or finally whether an object has a given key). When you want to compare two strings it’s more common to just use the equal sign
  2. Doing FROM "" doesn’t really bear any meaning, so it can be omitted. At least the "" part
  3. Using file.tags means that all nested tags are expanded, so if you’ve got the tags: tags: single, not/a/single, it’ll be expanded into single, not, not/a, not/a/single. To get each tag just once, use file.etags
  4. You should also be able to compare dates directly

This leaves us with this variant of your query:

```dataview
TABLE created as Created, updated as Modified, 
  join(file.etags, " ") as Tags, join(MOC, " ") as MOC
FROM  !"0. Journal" AND !"-. Templates"
WHERE created = this.file.day
   OR updated = this.file.day
```

And just for the fun of it, I don’t really think it looks nicer, but it showcases one possible use of contains: WHERE contains(list(created, updated), this.file.day) would check whether the newly created list of your dates, has the current files date in it.

1 Like

Hi, thanks for your comment

I’ve tried your query and works perfectly, many thanks. Only change I had to make for the query to work is to adapt the dates with dateformat() since the attributes created and updated are in format yyyy-MM-dd’T’HH:mm

The query is:

TABLE created as Created, updated as Modified, 
  join(file.etags, " ") as Tags, join(MOC, " ") as MOC
FROM  !"0. Journal" AND !"-. Templates"
WHERE dateformat(created, "yyyy-MM-dd") = dateformat(this.file.day, "yyyy-MM-dd")
   OR dateformat(updated, "yyyy-MM-dd") = dateformat(this.file.day, "yyyy-MM-dd")

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