i’m creating a note template for weekly notes where i want to list the books and articles i read in said week.
Things I have tried
first, i tried to get this information by way of using the creation date of my literature note. this worked just fine:
```dataview
LIST
WHERE econtains(type, "literature")
WHERE date(file.cdate).year = date(this.file.cday).year
WHERE date(file.cdate).weekyear = date(this.file.cday).weekyear
```
but there’s a missmatch of the creation date of the note and the day i read the book/article, therefore i added another parameter to the front matter:
reading-date: 30-08-2022
now, i don’t now how to make the dataview search work with this adaption. that’s why i’m reaching out to the community. may i ask you to be patient as i’m new to obsidian and not familiar with JS.
1.To filter by reading-date 2.To define a field variable s_rDate by using FLATTEN 3.To transform the value of reading-date into yyyy-MM-dd 4.To filter by date(s_rDate) 5.To display the result as a table
ONLY for reading-date field where the value is like dd-MM-yyyy
Notes
Summary
Q1: What is the same code to get the daily notes for a specific week compared with this.file.cday? (PS. I always create weekly notes on time.)
Summary_Q1
Original Example10
```dataview
WHERE date(s_rDate) != null
WHERE date(s_rDate).year = this.file.cday.year
WHERE date(s_rDate).weekyear = this.file.cday.weekyear
```
A1:
Another Example11
WW: ISO week number, padded to 2
```dataview
WHERE date(s_rDate) != null
WHERE dateformat(date(s_rDate), "yyyy_WW") = dateformat(this.file.cday , "yyyy_WW")
```
Q2: How to modify the following code to get the daily notes for a specific week compared with this.startDateOfWeek like “2022-09-19”? (PS. Sometimes I create the weekly notes later.)
```dataview
WHERE date(s_rDate) != null
WHERE dateformat(date(s_rDate), "yyyy_WW") = dateformat(this.file.cday , "yyyy_WW")
```
A2:
Another Example21
```dataview
WHERE date(s_rDate) != null
WHERE dateformat(date(s_rDate), "yyyy_WW") = dateformat(this.startDateOfWeek , "yyyy_WW")
```
OR
```dataview
WHERE date(s_rDate) != null
WHERE dateformat(date(s_rDate), "yyyy_WW") = dateformat(this.endDateOfWeek , "yyyy_WW")
```
Q3: How to modify the following code to get the daily notes for a specific week compared with this.yyyy_WW like “2022_38”? (PS. Sometimes I create the weekly notes later.)
Summary_Q3
Original Example30: To be modified
filename : 2022W38 // the current weekly note
---
yyyy_WW : 2022_38
---
```dataview
WHERE date(s_rDate) != null
WHERE dateformat(date(s_rDate), "yyyy_WW") = dateformat(this.file.cday , "yyyy_WW")
```
A3:
Another Example31
```dataview
WHERE date(s_rDate) != null
WHERE dateformat(date(s_rDate), "yyyy_WW") = this.yyyy_WW
```
Q4: How to modify the following code to get the daily notes for a specific week compared with this.file.name like “2022W38”? (PS. Sometimes I create the weekly notes later.)
Summary_Q4
Original Example40: To be modified
filename : 2022W38 // the current weekly note
```dataview
WHERE date(s_rDate) != null
WHERE date(s_rDate).year = this.file.cday.year
WHERE date(s_rDate).weekyear = this.file.cday.weekyear
```
A4:
Another Example41
```dataview
WHERE date(s_rDate) != null
WHERE dateformat(date(s_rDate), "yyyy_WW") = replace(this.file.name, "W", "_")
```
OR
```dataview
WHERE date(s_rDate) != null
WHERE date(s_rDate).year = number(split(this.file.name, "W")[0])
WHERE date(s_rDate).weekyear = number(split(this.file.name, "W")[1])
```
Code DQL10_transform_reading-date_into_yyyy-MM-dd
Summary_code
title: DQL10_transform_reading-date_into_yyyy-MM-dd =>ONLY for `reading-date` field where the value is like dd-MM-yyyy 1.To filter by `reading-date` 2.To define a field variable `s_rDate` by using `FLATTEN` 3.To transform the value of `reading-date` into yyyy-MM-dd 4.To filter by `date(s_rDate)` 5.To display the result as a table
collapse: close
icon:
color:
```dataview
TABLE WITHOUT ID
file.link AS "File",
s_rDate AS "s_rDate",
date(this.file.cday).weekyear AS "this_weekyear",
date(s_rDate).weekyear AS "weekyear"
FROM "100_Project/02_dataview/Q15_Reading/Q15_test_data"
WHERE econtains(type, "literature")
WHERE reading-date != null
FLATTEN regexreplace(reading-date, "^(\d{2})-(\d{2})-(\d{4})$", "$3-$2-$1") AS s_rDate
WHERE date(s_rDate) != null
WHERE date(s_rDate).year = this.file.cday.year
WHERE date(s_rDate).weekyear = this.file.cday.weekyear
```
great, this helps!
i further adapted the code so that the weekyear is not extracted from the creation date, but from the file name because sometimes i create the weekly notes later.
my version is this:
```dataview
LIST
FROM "3_knowledge-base"
WHERE econtains(type, "literature")
WHERE reading-date != null
FLATTEN regexreplace(reading-date, "^(\d{2})-(\d{2})-(\d{4})$", "$3-$2-$1") AS s_rDate
WHERE date(s_rDate) != null
WHERE date(s_rDate).year = this.file.cday.year
WHERE date(s_rDate).weekyear = number(split(this.file.name, "W")[1])
```
this works perfectly!
i also tried to use the same method for extracting the year from the filename, but for some reason this didn’t work. (run by itself it returns “2022” as the above function. any idea why id doesn’t work when implemented in the dataview code?
```dataview
WHERE date(s_rDate).year = number(split(this.file.name, "-",1))
```