I am building out my daily notes and want to include a Dataview query for files created on the date of the daily note. This will help me quickly see all content I generated on a given day. I want the query to be future-proof, so it will display files created on the same day as the daily note was created, regardless of when I view the note.
Things I have tried
This query uses the = operator and fails with the error Dataview: No results to show for table query. I suspect this is because file.ctime includes a time component, while date(this.file.name) might only represent the start of the day, causing the exact equality check to fail.
TABLE file.ctime as "Creation Time"
WHERE file.ctime = date(this.file.name)
SORT file.ctime DESC
LIMIT 10
This query uses the >= operator and works for today’s files, but will not work properly when I review the daily note in the future. For example, if I view a daily note from May 1st next week, this query would incorrectly show all files created from May 1st onwards, rather than just those created on May 1st.
TABLE file.ctime as "Creation Time"
WHERE file.ctime >= date(this.file.name)
SORT file.ctime DESC
LIMIT 10
Any guidance on how to correctly compare file.ctime to the daily note’s date, effectively ignoring the time component, would be greatly appreciated!
What are your file names, if it’s an ISO 8601 days, you’ll have that date available in this.file.day. Furthermore you could use file.cday to get the file system date of only the date when it was created.
Do however note that sync&backup can change this from your actual creation date.
Lastly, if you want to compare the date without the year part, you’ll need to either pull out the day and month from your date variables, or format the date without the year part.
So possibly something like ( file.cday.day = this.file.day.day AND file.cday.month = this.file.day.month ),
or alternatively dateformat(file.cday, "MM-dd") = dateformat(this.file.day, "MM-dd")
I might have misread your initial post, but that will indeed give you any files created on that exact date. I thought you wanted any file created on 27th May, or similar.
@holroy, I might have misread the initial post as well. Since your follow up did not show the end result, I shared the end result I came up with based on your input. Mine is all the notes created on the date of the current note, which I assumed was my daily note. This will work for daily notes created on the date they are for, but not for daily notes created early or late.
This is another reason why I advocate for not relying on the file system times, but rather use the template to insert either a date or created property into my notes. That way you can control it, and change it if need be. Like when you create daily notes on another date.
I don’t do it, but you can also setup Linter to add modification dates into a property also.
I get your point. Since my daily note’s name is “YYYY-MM-DD” and the files that I associate with that date start with "YYYY-MM-DD - " by using Note Refractor, I modified my script to the following:
TABLE file.outlinks as “Links”
WHERE contains( file.name, this.file.name) and file.name != this.file.name
SORT file.name
LIMIT 10