I’m trying to search my Reading List by Books finished in the Month of January for example.
In my YAML I’ve the key date_finished:2022-01-20.
But i can’t make Dataview find any titles for me, that i finished in that particular month. I’ve tried the Querytable title as "Titel", author as "Autor", date_finished as "finished" from "Books" WHERE contains(date_finished, "2022-01") sort date_finished desc
Many thanks in Advance
I’m apologising for my simple demand, but i am just overwhelmed by Dataview and its complicated queries.
But if I add a random time element to the yaml entry, it does work:
date_finished: 2022-01-20 11:59
The following works as a complete note, with the yaml on the top line:
```
---
title: A book
author: Nap
date_finished: 2021-09-11 11:59
tag: booksread
---
```dataview
TABLE
title as Titel,
author AS Autor
FROM #booksread
WHERE contains(date_finished, "2021")
```
Hi. If allowed to say something, I’d like to say this:
your date_finished: 2022-01-20 is in correct format → dataview recognize this value as a date (if you try the inline query =this.date_finished you’ll see the output format as a date);
(this is too to @anon12638239 ) if you use WHERE contains(date_finished, "2022-01") you’re asking as if date_finished is a string… what is not true. date_finished is read as a date. For example, for 2022-01-20, if you have in settings > dataview the date output format as MMMM dd, yyyy, then you get the expression “January 20th, 2022” (depend on your language, of course). So, if you ask for contains(date_finished, "2022-01") you don’t have it. But if we try to transform the date in a string and using contains(string(date_finished), "2022-01"), then you also get zero results, because the expression “January 20th, 2022” doesn’t have the string “2022-01”). But if you ask for contains(string(date_finished), "2022"), then you get all the cases with 2022.
this is the reason why @anon12638239 says that date_finished: 2022-01-20 doesn’t work and date_finished: 2022-01-20 11:59 works → because in this last example the format isn’t read as a date (is a wrong format for date with time… for that you need to use 2022-01-20T11:59). As a wrong date format, it’s read as a string.
so, to work with dates (for your query purposes) I suggest this:
```dataview
TABLE
title as "Titel",
author as "Autor",
date_finished as "finished"
FROM "Books"
WHERE date_finished.month = 1 AND date_finished.year = 2022
SORT date_finished DESC
```
(explaining)
with date_finished.month you can extract the month (the suffix .month) from your dates
with date_finished.year you can extract the year (the suffix .year) from your dates
so, filtering month = 1 (to check the format of the month output in a date you can use this inline query =this.date_finished.month) and the year (you don’t want notes from january 2021) you get your results.
Well, I understand about 0.000001% of that, which is a big improvement from where I started.
Joy!
---
title: A book
author: Nap
date_finished: 2021-09-11
tag: booksread
---
```dataview
TABLE
title as Titel,
author AS Autor
FROM
#booksread
WHERE
date_finished.month = 9
AND date_finished.year = 2021
```
Without others explanations (write explanations in fast way mode and in bad english isn’t the best option), a more simplified version:
```dataview
TABLE
title as "Titel",
author as "Autor",
date_finished as "finished"
FROM "Books"
WHERE dateformat(date_finished, "yyyy-MM") = "2022-01"
SORT date_finished DESC
```
(a fast explanation: if you convert the output format of the date to “yyyy-MM” - a string - then you can filter by the expression “2022-01”)