blacksmithgu / obsidian-dataview

A data index and query language over Markdown files, for https://obsidian.md/.
https://blacksmithgu.github.io/obsidian-dataview/
MIT License
7.11k stars 418 forks source link

DQL: Filtering dates witin a range doesn't work (aka using two WHERE filters with date comparisons) #2381

Open TerrorJacktyl opened 5 months ago

TerrorJacktyl commented 5 months ago

Problem

I have a list of notes in people/ who have birthdays. I'd like to write a query for all birthdays in the next month. For reference, today is 2024-06-27 for me, and I have written the example accordingly. You can adjust the birthdays to reproduce this example with date(now) instead of date("2024-06-27") by choosing one birthday for yesterday, one for tomorrow and one for two months away.

%% people/Alice.md %%
Birthday :: 2000-06-26 %% yesterday in 2000 %%

%% people/Bob.md %%
Birthday :: 2000-06-28 %% tomorrow in 2000 %%

%% people/Charlie.md %%
Birthday :: 2000-08-27 %% two months ahead in 2000 %%

%% Birthdays.md %%

1. Birthdays (this year) that are before 4 weeks from today. Lists Alice and Bob, but not Charlie, as expected.

```dataview
TABLE WITHOUT ID
file.link as "Name", date(date("2024-06-27").year + dateformat(Birthday, "-MM-dd")) as Birthday, date(date("2024-06-27").year + "-" + dateformat(Birthday, "MM-dd")) - date(now) as Happens
FROM "people"

WHERE (date(date("2024-06-27").year + "-" + dateformat(Birthday, "MM-dd"))) < date(now) + dur(4 w)
  1. Birthdays this year that are after today. Lists Bob and Charlie, as expected.
TABLE WITHOUT ID
file.link as "Name", date(date("2024-06-27").year + dateformat(Birthday, "-MM-dd")) as Birthday, date(date("2024-06-27").year + "-" + dateformat(Birthday, "MM-dd")) - date(now) as Happens
FROM "people"

WHERE (date(date("2024-06-27").year + "-" + dateformat(Birthday, "MM-dd"))) > date(now)
  1. Birthdays this year that are after today and less than four weeks from today (combining the filters from 1 and 2). Lists nobody, which is unexpected; we expect to see only Bob listed.
TABLE WITHOUT ID
file.link as "Name", date(date("2024-06-27").year + dateformat(Birthday, "-MM-dd")) as Birthday, date(date("2024-06-27").year + "-" + dateformat(Birthday, "MM-dd")) - date(now) as Happens
FROM "people"

WHERE (date(date("2024-06-27").year + "-" + dateformat(Birthday, "MM-dd"))) < date(now) + dur(4 w)
AND (date(date("2024-06-27").year + "-" + dateformat(Birthday, "MM-dd"))) > date(now)

# Expected behaviour

The following query should list only Bob.
TABLE WITHOUT ID
file.link as "Name", date(date("2024-06-27").year + dateformat(Birthday, "-MM-dd")) as Birthday, date(date("2024-06-27").year + "-" + dateformat(Birthday, "MM-dd")) - date(now) as Happens
FROM "people"

WHERE (date(date("2024-06-27").year + "-" + dateformat(Birthday, "MM-dd"))) < date(now) + dur(4 w)
AND (date(date("2024-06-27").year + "-" + dateformat(Birthday, "MM-dd"))) > date(now)


### Dataview Version

0.5.67

### Obsidian Version

1.6.5

### OS

MacOS
PeterBeckley commented 2 months ago

I can't seem to reproduce, works as expected (as long as I adjust my dates for today to keep the test consistent, and remove the comments after the birthdays). Is this still an issue if you update Obsidian?

image

Obsidian 1.6.7 - installer 1.6.5 Dataview 0.5.67 Windows 11 (I know, I know)