I have a bunch of notes about upcoming shows, all of which contain an ISO 8601 date with a timestamp in their frontmatter simply called “date”. I am trying to use a DataviewJS query to show me all of the events on a given day. This is easy in a regular dataview query, but I am trying to expand it into a dynamic weekly overview.
Things I have tried
This query shows me all notes in the folder which have a date field
if I add 'where(p => p.date == dv.date(“2025-06-12”))` there is no output. I’ve found several old forum posts with similar issues, and every comparison I test in this query either results in no output or a list of all notes under that folder with a defined date.
I don’t have a lot of experience with JS, but some of the other forum posts I’ve been reading indicate that the ISO date objects need to be parsed to something else before I can work with them. I was able to create luxon DateTime objects and an interval to define the day that I’m trying to search in:
But that’s about as far as my JavaScript experience will take me. I don’t know how to use those objects in the .where() field, if that’s even the right workaround. Do I need to convert my existing ISO objects to luxon objects? Can that happen in the DataviewJS code block after I’ve pulled them with dv.pages() or do I need to add another property to each note? Am I just missing something extremely obvious?
Date comparisons is a hassle, and can be very confusing since DQL and Dataviewjs uses different date time libraries, and in addition you can call on e or the other from javascript. And they differ in how they compare against each other. In general doing “some date” == “another date” will fail.
Thank you so much! I re-created your example and the output was correct on the note and in console, but when I add .where(p => p.date.equals(dv.date("2025-06-12"))) it returns “TypeError: Cannot read properties of undefined (reading ‘equals’)”
Any ideas? My notes also have timestamps-- not sure if that affects anything since I’m creating a date object before comparing them, but I think it would prevent me from using ==.
That just means that some of your files don’t have that date property. So you’ll need to do a separate query to find those files and add it, or add a safeguard like in .where(p => p.date && p.date.equals(dv.date(...)). An alternate notation doing mostly the same: .where(p => p.date?.equals(dv.date(...))
I see, thanks! Using p.date?.equals(dv.date(...)) returns the list I’m looking for, but only if I remove the TXX:XX from the note’s date property. I’m not opposed to separating the properties in each note, but is there a way to make the .where statement only check for the date portion?
This is where it would have been easier to format the dates as strings in the ISO 8601 format, and do a string comparison.
However, you can use something like dv.date(p.date?.toDateString()) to remove the time part, and surely many other variants. I’ve not tested this variant, so it could have some side effects when the p.date is undefined.