Well, Here I Am Again With Another Major Problem

What I’m trying to do

I am trying to create a simple Daily Notes Template that includes a dataview query that shows me in a list all the files I created the day before. Should be simple, right? Right…

Things I have tried

I have searched EVERYWHERE in the Dataview documentation about dates, date functions, literals, and every other possible permutation from there and Reddit and general Google searches. I got nothing.

This is what I originally tried, which seemed to work:

WHERE creation-date = date(today) - dur(1 day)
SORT file.day DESC

That seemed to work - for a few days.

Today I notice I get “no results found”.

So I try all sorts of things like this:

FROM "Periodic Notes/Daily Notes"
WHERE striptime(date(creation-date)) = striptime(date(today)) - dur(1 day)

The problem is the query returns nothing even though there are AT LEAST two Daily Notes files that explicitly have creation dates of January 20 and 21. They don’t show up at all. If I change the dur field to 4 days, it goes all the way back to the 19th and find THAT file.

Why is it completely missing the two Daily Notes files from the 20th and 21st? If I hover over those files, they explicitly show creation dates that are correct.

I also ran simple queries just to list out the creation dates of all the files in that folder. Like this:

LIST WITHOUT ID striptime(date(yesterday))
SORT file.day DESC

That works fine, shows me yesterday’s files. But if I run a query like this:

WHERE striptime(date(creation-date)) - dur(4 days)
SORT file.day DESC

It only shows me files from the 17th to the 19th - no 20 or 21. Yet those two Daily Notes have perfectly good front matter with correct creation dates placed there by a Templater command which is correct and functions fine.

It’s driving me nuts.

What is the correct query to show all files created yesterday from a creation-date parameter in date format in the front matter?

I have to say the documentation on things like date comparisons could use a hell of a lot more examples of the sort one usually finds in SQL function documentation or textbooks. This has just driven me crazy, I’ve spent hours on this.

I previous had that issue with an incorrect creation time being reported. I beginning to believe that I can’t trust Obsidian time functions on openSUSE Tumbleweed with the BTRFS file system.

I think I have it fixed. If I use this query it appears to convert the creation-date text string into a proper date with the time aspects set to zero by the striptime function and this appears to match the format returned by the literal date(yesterday) which also has the time aspects set to zero.

It turns out the issue was that the format templater uses for the file creation date has the hours set to 24 hour time and the format dataview uses for date(yesterday) is 12 hour time, so I have to use an explicit format for the creation date and then strip out the time.

Ridiculous amount of effort involved in this, sending me down rabbit holes of Luxon, moment,js, templater, dataview literals and functions.


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