Dataview file.cday is not working

What I’m trying to do

I’m trying to make a weekly review note where I could review my past week created notes and reflect on them. Hence, I want to make a dataview query so that I could get the date, summary and tags of the last 7 days relative to that weekly review note. The problem is that rather than getting a list of notes of the last 7 days relative to that weekly review note, I get the notes of the last 7 days from now.

TABLE file.cday as "Date", Summary, tags as "Type"
FROM "" AND !"1000 Templates"
WHERE file.cday >= (this.file.cday - dur(7 days)) AND !contains(tags,"Definitions")
SORT file.cday DESC

Things I have tried

I have tried changing this.file.cdate to this.file.ctime to no avail.

Check in your file system whether the ctime value of the note containing your DataView query is what you expect. You might find that the ctime matches the last modification time.

This has happened to me with many notes — when I edit them, not only does the mtime (modification time) change, but the ctime does too. It’s as if the note is being deleted and recreated instead of just modified. I’m not entirely sure why this happens, but I suspect OneDrive might be the culprit. Are your notes stored in OneDrive?

Copying the text version it looks like you start with 3 backticks only. If this is correct just add “dataview” to the string, ie ```data view

image

Weirdly enough, the file.ctime is what is expected. However, you’re right about my files being in Onedrive

I forgot to include ```dataview but I did so in my actual query

I’ve figured it out. After prompting copilot for a while, the reason this query does not work is that this.file.ctime is not interpreted as a proper date format when using function WHERE. This means that you can’t apply proper arithmetic to it. It would cause some unexpected results. My solution instead is to create a seperate metadata key/field date and use templater to insert the date in the relevant format at note creation. Then, simply, compare to that key, in this case date. You could compare values by using `this.{key}'. my final working query is:

TABLE file.ctime as "Date", Summary, tags as "Type"
FROM "" AND !"1000 Templates"
WHERE file.ctime >= (date(this.date) - dur(7 days)) 
AND file.ctime <= date(this.date)
AND !contains(tags,"Definitions")
AND file.path != this.file.path

SORT file.ctime DESC

Hope this is helpful to you!

1 Like