Dataview plugin snippet showcase

Topic

Summary
  • How to get daily notes for a specific week via the format like “yyyy_WW”? (DQL10)
  • How to get daily notes for a specific week via the format like “yyyy_WW”(To offset one week)? (DQL20)
  • How to design a weekly note?
    • DQL10_Q1 : via this.startDateOfWeek like “1974-02-21”
    • DQL10_Q2 : via this.yyyy_WW like “1974_08”
    • DQL10_Q3 : via this.file.name like “1974_08”
    • DQL10_Q4 : via this.file.cday (PS. I have never created the weekly notes later.)

Test

Summary
  • dataview: v0.5.46

Input

Summary

the current weekly note

Summary_weekly_note
  • filename : 1974W08 // DQL10_Q3 used
  • this.file.cday = date(“1974-02-21”) // DQL10_Q4 used
  • The YAML field startDateOfWeek(or endDateOfWeek) is used by the DQL10 or DQL10_Q1.
  • The YAML field yyyy_WW is used by the DQL10_Q2.
---
yyyy_WW : 1974_08
startDateOfWeek : 1974-02-18
endDateOfWeek   : 1974-02-24
---

### DQL10


### DQL20



dictionary files

Summary_daily_notes
  • Location: “100_Project/02_dataview/Q22_WeeklyNote/Q22_test_data”

folder: 1974_08 (“yyyy_WW”)

Summary_1974_08
  • filename : 1974-02-18
---
Date: 1974-02-18
workout: 30 minutes
---


  • filename : 1974-02-19
---
Date: 1974-02-19
workout: 60 minutes
---


  • filename : 1974-02-20
---
Date: 1974-02-20
workout: 90 minutes
---


  • filename : 1974-02-21
---
Date: 1974-02-21
workout: 120 minutes
---


  • filename : 1974-02-22
---
Date: 1974-02-22
workout: 90 minutes
---



  • filename : 1974-02-23
---
Date: 1974-02-23
workout: 60 minutes
---



  • filename : 1974-02-24
---
Date: 1974-02-24
workout: 30 minutes
---



folder: 1974_09 (“yyyy_WW”)

Summary_1974_09
  • filename : 1974-02-25
---
Date: 1974-02-25
workout: 20 minutes
---



  • filename : 1974-02-26
---
Date: 1974-02-26
workout: 50 minutes
---



  • filename : 1974-02-27
---
Date: 1974-02-27
workout: 70 minutes
---



  • filename : 1974-02-28
---
Date: 1974-02-28
workout: 80 minutes
---



  • filename : 1974-03-01
---
Date: 1974-03-01
workout: 70 minutes
---



  • filename : 1974-03-02
---
Date: 1974-03-02
workout: 50 minutes
---



  • filename : 1974-03-03
---
Date: 1974-03-03
workout: 20 minutes
---



DQL10_get_daily_notes_for_a_specific_week_via_yyyy_WW

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL10
_get_daily_notes
_for_a_specific_week
_via_yyyy_WW
startDateOfWeek:
a string like yyyy-MM-dd
(in the current weekly note)
no 1.To filter by workout
2.To filter by date(file.name)
3.To filter by the format like “yyyy_WW”
4.To sort by file.name in ascending order
5.To display the result as a table
To require the YAML field startDateOfWeek in the current weekly note

Notes

Summary

Q1: What is the same code to get the daily notes for a specific week compared with this.startDateOfWeek?

Summary_Q1
Original Example: Q1 (To be modified)
```dataview
WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = dateformat(this.startDateOfWeek , "yyyy_WW")
```

A1:

Another Example: A1_11
```dataview
WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = dateformat(this.endDateOfWeek , "yyyy_WW")
```
Another Example: A1_12
```dataview
WHERE date(file.name) != null
WHERE date(file.name).year = this.startDateOfWeek.year
WHERE date(file.name).weekyear = this.startDateOfWeek.weekyear
```

Q2: How to modify the following code to get the daily notes for a specific week compared with this.yyyy_WW like “1974_08”? (PS. Sometimes I create the weekly notes later.)

Summary_Q2
Original Example: Q2 (To be modified)
  • filename : 1974W08(the current weekly note)
---
yyyy_WW : 1974_08
startDateOfWeek : 1974-02-18
endDateOfWeek   : 1974-02-24
---
```dataview
WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = dateformat(this.startDateOfWeek , "yyyy_WW")
```

A2:

Another Example: A2_21
```dataview
WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = this.yyyy_WW
```
Another Example: A2_22
```dataview
WHERE date(file.name) != null
WHERE date(file.name).year = number(split(this.yyyy_WW, "_")[0] )
WHERE date(file.name).weekyear = number(split(this.yyyy_WW, "_")[1])
```

Q3: 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_Q3
Original Example: Q3 (To be modified)
  • filename : 1974W08 // the current weekly note
```dataview
WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = dateformat(this.startDateOfWeek , "yyyy_WW")
```

A3:

Another Example: A3_31
```dataview
WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = replace(this.file.name, "W", "_")
```
Another Example: A3_32
```dataview
WHERE date(file.name).year = number(split(this.file.name, "W")[0])
WHERE date(file.name).weekyear = number(split(this.file.name, "W")[1])
```

Q4: How to modify the following code to get the daily notes for a specific week compared with this.file.cday? (PS. I have never created the weekly notes later.)

Summary_Q4
Original Example: Q4 (To be modified)
  • filename : 1974W08 // the current weekly note
  • this.file.cday = date(“1974-02-21”) // DQL10_Q4 used
---
yyyy_WW : 1974_08
startDateOfWeek : 1974-02-18
endDateOfWeek   : 1974-02-24
---
```dataview
WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = dateformat(this.startDateOfWeek , "yyyy_WW")
```

A4:

Another Example: A4_41
```dataview
WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = dateformat(this.file.cday , "yyyy_WW")
```
Another Example: A4_42
```dataview
WHERE date(file.name) != null
WHERE date(file.name).year = this.file.cday.year
WHERE date(file.name).weekyear = this.file.cday.weekyear
```

Code DQL10_get_daily_notes_for_a_specific_week_via_yyyy_WW

Summary_code
title: DQL10_get_daily_notes_for_a_specific_week_via_yyyy_WW => 0.To require the YAML field `startDateOfWeek` in the current weekly note 1.To filter by `workout` 2.To filter by `date(file.name)` 3.To filter by the format like "yyyy_WW" 4.To sort by `file.name` in ascending order 5.To display the result as a table
collapse: close
icon: 
color: 
```dataview
TABLE WITHOUT ID
      file.link AS "File",
      workout AS "workout",    
      dateformat(date(file.name), "yyyy_WW") AS "Daily Notes",
      dateformat(this.startDateOfWeek , "yyyy_WW")  AS "Current Weekly Note"

FROM "100_Project/02_dataview/Q22_WeeklyNote/Q22_test_data"
WHERE workout

WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = dateformat(this.startDateOfWeek , "yyyy_WW")

SORT file.name ASC

```

Screenshots(DQL10)


DQL20_get_daily_notes_for_a_specific_week_via_yyyy_WW_and_offset_one_week

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL20
_get_daily_notes
_for_a_specific_week
_via_yyyy_WW
_and
_offset_one_week
startDateOfWeek:
a string like yyyy-MM-dd
(in the current weekly note)
no 1.To filter by workout
2.To filter by date(file.name)
3.To filter by the format like “yyyy_WW”(To offset one week)
4.To sort by file.name in ascending order
5.To display the result as a table
To require the YAML field startDateOfWeek in the current weekly note

Notes

Summary

Q1: What is the same code to get the daily notes for a specific week compared with this.startDateOfWeek(To offset one week)?

Summary_Q1
Original Example: Q1 (To be modified)
```dataview
WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = dateformat(this.startDateOfWeek + dur("1 week") , "yyyy_WW")
```

A1:

Another Example: A1_11
```dataview
WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = dateformat(this.endDateOfWeek + dur("1 week") , "yyyy_WW")
```
Another Example: A1_12

Limitation: Suppose that the year of the daily notes is the same as this.startDateOfWeek.year .

```dataview
WHERE date(file.name) != null
WHERE date(file.name).year = this.startDateOfWeek.year
WHERE date(file.name).weekyear = this.startDateOfWeek.weekyear + 1 
```
Another Example: A1_13

Limitation: Suppose that the year of the daily notes is the same as this.startDateOfWeek.year .

```dataview
WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = string(this.startDateOfWeek.year) + "_" + padleft(string(this.startDateOfWeek.weekyear + 1), 2, "0")
```

Q2: How to modify the following code to get the daily notes for a specific week compared with this.yyyy_WW like “1974_08”(To offset one week)? (PS. Sometimes I create the weekly notes later.)

Summary_Q2
Original Example: Q2 (To be modified)
  • filename : 1974W08 // the current weekly note
---
yyyy_WW : 1974_08
startDateOfWeek : 1974-02-18
endDateOfWeek   : 1974-02-24
---
```dataview
WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = dateformat(this.startDateOfWeek + dur("1 week") , "yyyy_WW")
```

A2:

Another Example: A2_21

Limitation: Suppose that the year of the daily notes is the same as this.startDateOfWeek.year .

```dataview
WHERE date(file.name) != null
WHERE date(file.name).year = number(split(this.yyyy_WW, "_")[0] )
WHERE date(file.name).weekyear = number(split(this.yyyy_WW, "_")[1]) + 1
```
Another Example: A2_22

Limitation: Suppose that the year of the daily notes is the same as this.startDateOfWeek.year .

```dataview
WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = split(this.yyyy_WW, "_")[0] + "_" + padleft(string(number(split(this.yyyy_WW, "_")[1]) + 1), 2, "0")
```

Q3: How to modify the following code to get the daily notes for a specific week compared with this.file.name like “2022W38”(To offset one week)? (PS. Sometimes I create the weekly notes later.)

Summary_Q3
Original Example: Q3 (To be modified)
  • filename : 1974W08 // the current weekly note
```dataview
WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = dateformat(this.startDateOfWeek + dur("1 week") , "yyyy_WW")
```

A3:

Another Example: A3_31

Limitation: Suppose that the year of the daily notes is the same as this.startDateOfWeek.year .

```dataview
WHERE date(file.name).year = number(split(this.file.name, "W")[0])
WHERE date(file.name).weekyear = number(split(this.file.name, "W")[1]) + 1 
```
Another Example: A3_32

Limitation: Suppose that the year of the daily notes is the same as this.startDateOfWeek.year .

```dataview
WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = split(this.file.name, "W")[0] + "_" + padleft(string(number(split(this.file.name, "W")[1]) + 1), 2, "0")
```

Q4: How to modify the following code to get the daily notes for a specific week compared with this.file.cday(To offset one week)? (PS. I have never created the weekly notes later.)

Summary_Q4
Original Example: Q4 (To be modified)
  • filename : 1974W08 // the current weekly note
  • this.file.cday = date(“1974-02-21”) // DQL10_Q4 used
---
yyyy_WW : 1974_08
startDateOfWeek : 1974-02-18
endDateOfWeek   : 1974-02-24
---
```dataview
WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = dateformat(this.startDateOfWeek + dur("1 week") , "yyyy_WW")
```

A4:

Another Example: A4_41
```dataview
WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = dateformat(this.file.cday + dur("1 week") , "yyyy_WW")
```
Another Example: A4_42

Limitation: Suppose that the year of the daily notes is the same as this.startDateOfWeek.year .

```dataview
WHERE date(file.name) != null
WHERE date(file.name).year = this.file.cday.year
WHERE date(file.name).weekyear = this.file.cday.weekyear + 1
```

Code DQL20_get_daily_notes_for_a_specific_week_via_yyyy_WW_and_offset_one_week

Summary_code
title: DQL20_get_daily_notes_for_a_specific_week_via_yyyy_WW_and_offset_one_week => 0.To require the YAML field `startDateOfWeek` in the current weekly note 1.To filter by `workout` 2.To filter by `date(file.name)` 3.To filter by the format like "yyyy_WW"(To offset one week) 4.To sort by `file.name` in ascending order 5.To display the result as a table
collapse: close
icon: 
color: 
```dataview
TABLE WITHOUT ID
      file.link AS "File",
      workout AS "workout",    
      dateformat(date(file.name), "yyyy_WW") AS "Daily Notes",
      dateformat(this.startDateOfWeek , "yyyy_WW")  AS "Current Weekly Note",
      dateformat(this.startDateOfWeek + dur("1 week") , "yyyy_WW")  AS "Current Weekly Note(offset one week)"
      
FROM "100_Project/02_dataview/Q22_WeeklyNote/Q22_test_data"
WHERE workout

WHERE date(file.name) != null
WHERE dateformat(date(file.name), "yyyy_WW") = dateformat(this.startDateOfWeek + dur("1 week") , "yyyy_WW")

SORT file.name ASC

```

Screenshots(DQL20)


Conclusion

Summary
  • According to the codes and notes above, there is a summary as follows.
  • To get daily notes for a specific week via the format like “yyyy_WW”(To offset n weeks or not), the better solution is using the field startDateOfWeek.
  • As a result, the original YAML fields in the current weekly note can be simplified as follows.

  • filename : 1974W08 // You can rename it as needs.
---
startDateOfWeek : 1974-02-18
---
endDateOfWeek :: `=this.startDateOfWeek + dur("6 days")`   
yyyy_WW :: `=dateformat(this.startDateOfWeek , "yyyy_WW")`


### DQL10


### DQL20




Reference

Summary