Dataview – query mismatched file names and date fields

Hello.

  1. All file names are in YYYY-MM-DD format
  2. All files have a Date field also in YYYY-MM-DD format
  3. I want to check that file names match Date fields
  4. In the query above, file name 2025-01-03 has a mismatched Date field of 2024-11-06
  5. Can I get Dataview to only list mismatched files?
  6. I have tried querying against file.day, file.name, file.link, and file.frontmattter.Date
---
Date: 2024-11-06
---

```dataview
TABLE
Date
WHERE file.link != Date
SORT file.name ASC
```

1. All file names are in `YYYY-MM-DD` format
2. All files have a `Date` field also in `YYYY-MM-DD` format
3. I want to check that file names match `Date` fields
4. In the query above, file name `2025-01-03` has a mismatched `Date` field of `2024-11-06`
5. Can I get Dataview to only list mismatched files?
6. I have tried querying against `file.day`, `file.name`, `file.link`, and `file.frontmattter.Date`

With thanks

Figured it out … eventually. :person_facepalming:

Leaving this here in case it might help anyone else:


```dataview
TABLE
Date
WHERE date(file.name) != Date
LIMIT 10
SORT file.name ASC
```

Given that the file name contains a “YYYY-MM-DD” somewhere within the file name (or if there is a property called date which uses the same format), you can use file.day to get that date.

So using file.day, you could have used WHERE file.day != Date too. And that would’ve given a match even if you file was named “My glorious note from 2025-02-19 on the subject of dates”.

Along a line of verifying the property, it’s needed that it strictly follows the ISO 8601 date format (in the source form), so if that had been a problem of yours you could possibly use some query like the following:

```dataview
TABLE file.day, file.frontmatter.Date as "Prop-Date", typeof(Date) as "Prop-type"
WHERE file.day
  AND (typeof(Date) != "date" OR file.day != Date)
```

This would pick up if you had problems with the writing of the Date property, and if it was different from the date in the file name. (That is, given I’ve not done any stupid typos in my untested query)

1 Like

Thanks. I expected file.day to work originally, but it didn’t. :person_shrugging:

Here are the queries I tested:

---
Date: 2024-11-06
---

## Mismatch against file.name

```dataview
TABLE
Date
WHERE date(file.name) != Date
WHERE Date
SORT file.name ASC
```

## file.day = no results

```dataview
TABLE
Date
WHERE file.day != Date
WHERE Date
SORT file.name ASC
```

## file.frontmatter.Date = no results

```dataview
TABLE file.day, file.frontmatter.Date as "Prop-Date", typeof(Date) as "Prop-type"
WHERE file.day
  AND (typeof(Date) != "date" OR file.day != Date)
```

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