Checking for the date of multiple identical fields

What I’m trying to do

I have a note with the tag “people”. Each note may have several dates associated with this person.

I want to make it so that I have notes displayed in my daily note, where the “:gift:” field coincides with the date of the note.

Problem: the note is shown in the sheet only if there are all three fields in the note with the tag people, otherwise, if you use one or two fields, nothing is displayed on the right day

I apologize for these “:gift:”, I use this field only for clarity

Things I have tried

I have two notes. They contain fields:

First note:
[:gift::: 07.11.2023]

Date one
[:gift::: 10.10.2023]

Date two
[:gift::: 11.10.2023]

Second note:
[:gift::: 07.11.2023]

This is a request from my daily note:

FROM #people 

  (length(🎁[0]) > 0 AND 
  contains((this.file.cday).month, date(🎁[0], "dd.MM.yyyy").month) AND 
  contains((this.file.cday).day, date(🎁[0], "dd.MM.yyyy").day))
  (length(🎁[1]) > 0 AND 
  contains((this.file.cday).month, date(🎁[1], "dd.MM.yyyy").month) AND 
  contains((this.file.cday).day, date(🎁[1], "dd.MM.yyyy").day))
  (length(🎁[2]) > 0 AND 
  contains((this.file.cday).month, date(🎁[2], "dd.MM.yyyy").month) AND 
  contains((this.file.cday).day, date(🎁[2], "dd.MM.yyyy").day))


  1. Example where all three fields are used:
    Screenshot 2023-11-08 131440

  2. There’s one field here, because I don’t need to use the other two:

  3. Оutput:

Although in both notes the date is the same and two notes should have been written
WHAT am I doing wrong? Why don’t the OR operators work?

As long as you define your inline fields outside of a list/task context, they’re all gobbled up into a list, and you’re making it harder for yourself to query on parts of that list of dates.

Using your example, we could do these quiries:

## Original field single/list

TABLE 🎁, flat(list(🎁))
WHERE file.folder = this.file.folder

## FLATTEN the values

FLATTEN flat(list(🎁)) as aDate
WHERE file.folder = this.file.folder

Which renders as follows with your two test files:

Notice how in the first query second column that the file with multiple dates list them as a list, while the single value is just a single value. This causes hammock when trying to compare against anything as the former needs to use contains() & co, and the latter needs to use the equality operator. This can however be countered by forcing everything into a list, using the flat(list( ... )) trickery. See third column for the result of this trickery. Now we can use contains() against any variant single or list. :smiley:

Also note in the first query how all the dates are bungled together and displayed as one row. In the second query we flatten the list into single items, and get a table with four rows. Now we can only also limit the result to any of those dates.

However, in neither of these queries are you able to associate the text of “Birthday” or “Date one” and so on to the actual date itself…

Using lists

If on the other hand you used definitions like:

First note:
- (dateType:: Birthday) [💝:: 07.11.2023]
- (dateType:: Date one) [💝:: 10.10.2023]
- (dateType:: Date two) [💝:: 11.10.2023]

Second note:

- (dateType: Birthday) [💝:: 07.11.2023]

We could a query like the following:

TABLE item.dateType, item.💝
FLATTEN file.lists as item
WHERE item.dateType

And get the result:

Finally, we’re getting somewhere close to checking a single date against something. There is just one hurdle left to pass, and that is that “07.11.2023” isn’t recognised as a date directly by dataview. So either you need to format the date of the daily note into that format using dateformat(...), or we need to make the field into a date using something like date(item.💝, "dd.MM.yyyy")

Using the latter we could do a query like:

TABLE item.dateType, item.💝, date(item.💝, "dd.MM.yyyy")
FLATTEN file.lists as item
WHERE item.dateType
  AND date(item.💝, "dd.MM.yyyy") = date("2023-11-07")

Still using the same test data this displays the following table:

Where you could replace the last date("2023-11-07") with given that your daily note has a properly set date (or use the same date conversion as suggested for item.💝).

PS! Using file.cday is not a reliable way to check for the creation date, as it might be changed during various file synchronisation issues, backup/restore issues and so on. You’re better of either setting the creation date using date: ... or by including the ISO-date into the file name itself. Then you can access this date using

1 Like

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