Dataview query for invalid dates

One thread you didn’t find in your search is this reply:

In there I list some related information on why this is hard to do in a DQL query, and how you need to use dataviewjs to actually locate the ones without values. The DQL version (which will not list empty values) for your specific use case:

```dataview
TABLE date, typeof(date)
WHERE date AND typeof(date) != "date"
```

The proper way to use this, using dataviewjs, is a little more complex, and looks as follows:

```dataviewjs
const pages = dv.pages()
  .where( p => p.hasOwnProperty("date") )
  .mutate( p => {
   if ( p.date ) {
     p.typeOf = (
       typeof( p.date ) == "object" ? 
       p.date.constructor.name :
       typeof( p.date ) 
     )
   } else {
     p.typeOf = "null"
    }    
  })
  .where(p => p.typeOf != "DateTime" )
  
dv.table(["Note", "date", "typeOf(date)"],
   pages.map( p => [ p.file.link, p.date, p.typeOf ] ) )
```

The trickery related to .mutate looks a bit deeper into the type of objects in an attempt to discover the pure DateTime objects, and it adds its findings into a new field, p.typeOf. This in the used in the next line to eliminate those which are true dates.

In a simple test setup of mine this results in the following output:

If you find it more natural for you, feel free to change the p.typeOf = "null" into p.typeOf = "empty" or some text which make more sense to you. And of course, replace any occurence of p.date with p.startdate or whatever date field you want to test against.

1 Like