Dataviewjs - files in current week

Topic

Summary
  • How to get the files for the current week with DQL? (DQL10)
  • How to get the files for the current week with DVJS? (DVJS10)

Test

Summary
  • dataview: v0.5.55

Input

Summary

the current note

  • Location: “100_Project/01_dataviewjs/01_by_example/Q31_WeeklyNote”
  • filename : 19600229_WeeklyNote
```md
---
today: 1960-02-29
---

### Q31_DQL10 (OR Q31_DVJS10)


```

dictionary files

  • Location: “100_Project/01_dataviewjs/01_by_example/Q31_WeeklyNote/Q31_test_data”

folder: 1960_09

  • filename : Daily-19600229-Mon
```yaml

```

  • filename : Daily-19600301-Tue
```yaml

```

  • filename : Daily-19600302-Wed
```yaml

```

  • filename : Daily-19600303-Thu
```yaml

```

  • filename : Daily-19600304-Fri
```yaml

```

  • filename : Daily-19600305-Sat
```yaml

```

  • filename : Daily-19600306-Sun
```yaml

```

DQL10_get_files_for_current_week_from_file_name_and_TABLE

NOTE:
Replace date(this.today) with date(“today”) before you begin to use the DQL10.

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL10
_get_files
_for_current_week
_from_file_name
_and_TABLE
file.name: a string
1.Daily-19600229-Mon
2.Daily-19600301-Tue
7.Daily-19600306-Sun

dateformat(s_ISOdate, "yyyy_WW"):
1.yyyy = four- to six- digit year, pads to 4
2.WW = ISO week number, padded to 2
no 1.To filter by file.name
2.To define a field variable s_ISOdate
3.To filter by date(s_ISOdate)
4.To filter by dateformat(date(s_ISOdate), "yyyy_WW")
5.To sort by file.name in ascending order 6.To display the result as a table
Note:
1.The DQL10 requires a field today, defined as 1960-02-29 on the current page
2.Replace date(this.today) with date(“today”) before you begin to use the DQL10.

Code DQL10_get_files_for_current_week_from_file_name_and_TABLE

Summary_code
title: DQL10_get_files_for_current_week_from_file_name_and_TABLE =>0.The DQL10 requires a field `today`, defined as 1960-02-29 on the current page 1.To filter by `file.name` 2.To define a field variable `s_ISOdate` 3.To filter by `date(s_ISOdate)` 4.To filter by `dateformat(date(s_ISOdate), "yyyy_WW")` 5.To sort by `file.name` in ascending order 6.To display the result as a table
collapse: close
icon: 
color: 
```dataview
TABLE WITHOUT ID
      file.link AS "FILE",
      s_ISOdate AS "s_ISOdate",
      dateformat(date(s_ISOdate), "yyyy_WW") AS "yyyy_WW_s_ISOdate",
      dateformat(date(this.today), "yyyy_WW") AS "yyyy_WW_this.today"

FROM "100_Project/01_dataviewjs/01_by_example/Q31_WeeklyNote/Q31_test_data"
WHERE startswith(file.name, "Daily-")


FLATTEN regexreplace(file.name, "^Daily-(\d{4})(\d{2})(\d{2})-[FMSTW][aehoru][deintu]$", "$1-$2-$3") AS s_ISOdate


WHERE date(s_ISOdate)
WHERE dateformat(date(s_ISOdate), "yyyy_WW") = dateformat(date(this.today) , "yyyy_WW")
SORT file.name ASC
      
```

Screenshots(DQL10): today=“1960-02-29”


DVJS10_get_files_for_current_week_from_file_name_and_TABLE

NOTE:
Replace let today = dv.current().today with let today = “today” before you begin to use the DVJS10.

Summary

Main DVJS

Code Name Data type Group By Purposes Remark
DVJS10
_get_files
_for_current_week
_from_file_name
_and_TABLE
file.name: a string
1.Daily-19600229-Mon
2.Daily-19600301-Tue
7.Daily-19600306-Sun

dateformat(s_ISOdate, "yyyy_WW"):
1.yyyy = four- to six- digit year, pads to 4
2.WW = ISO week number, padded to 2
no 1.To filter by file.name
2.To define a variable s_ISOdate
3.To filter by date(s_ISOdate)
4.To filter by dateformat(date(s_ISOdate), "yyyy_WW")
5.To sort by file.name in ascending order 6.To display the result as a table
Note:
1.The DVJS10 requires a field today, defined as 1960-02-29 on the current page
2.Replace dv.date(today) with dv.date(“today”) before you begin to use the DVJS10.

Code DVJS10_get_files_for_current_week_from_file_name_and_TABLE

Summary_code
title: DVJS10_get_files_for_current_week_from_file_name_and_TABLE =>0.The DVJS10 requires a field `today`, defined as 1960-02-29 on the current page  1.To filter by `file.name` 2.To define a variable `s_ISOdate` 3.To filter by `date(s_ISOdate)` 4.To filter by `dateformat(date(s_ISOdate), "yyyy_WW")` 5.To sort by `file.name` in ascending order 6.To display the result as a table
collapse: close
icon: 
color: 
```dataviewjs
// M10. define today:
// A field `today`, defined as 1960-02-29 on the current page, helps for debugging. 
// Replace let today = dv.current().today with let today = "today" before you begin to use the DVJS10.
// #####################################################################
// let today = "today";
let today = dv.current().today;


// M11. define pages: gather relevant pages
// #####################################################################
let pages = dv
    .pages(
        '"100_Project/01_dataviewjs/01_by_example/Q31_WeeklyNote/Q31_test_data"'
    )
    .where((page) => dv.func.startswith(page.file.name, "Daily-"))
    .where((page) => {
        
        // M11.WH10 define s_ISOdate: get an ISOdate string from page.file.name
        // ##################################################################### 
        let s_ISOdate = page.file.name.replace(
            /^Daily-(\d{4})(\d{2})(\d{2})-[FMSTW][aehoru][deintu]$/,
            "$1-$2-$3"
        );
        
        
        // M11.WH20 check if dv.date(s_ISOdate) is an ISO date: 
        // ##################################################################### 
        if (dv.date(s_ISOdate) === null) {
            return false;
        }
        
        
        // M11.WH30 filter by `dateformat(date(s_ISOdate), "yyyy_WW")` : 
        // ##################################################################### 
        if (
            dv.func.dateformat(dv.date(s_ISOdate), "yyyy_WW") ===
            dv.func.dateformat(dv.date(today), "yyyy_WW")
        ) {
            return true;
        } else {
            return false;
        }

        
    })
    .sort((page) => page.file.name, "asc");


// M51. output pages:
// #####################################################################
//dv.header(3, "M51.output pages");
dv.table(
    ["FILE", "yyyy_WW_this.today"],
    pages.map((page) => [
        page.file.link,
        dv.func.dateformat(dv.date(today), "yyyy_WW"),
    ])
);

      
```

Screenshots(DVJS10): today=“1960-02-29”


Reference

Summary

Q22_WeeklyNote: Main

```dataview

WHERE dateformat(date(file.name), "yyyy_WW") = dateformat(date("today") , "yyyy_WW")
```

Q26_ReadingExercise: DQL20

  • Q26_ReadingExercise: Part01: Solutions
    • DQL20_filter_by_Reading_or_Exercise_group_by_P_isoDate_from_file_name_and_TABLE

Q15_Reading: Regular Expressions

```dataview

FLATTEN regexreplace(reading-date, "^(\d{2})-(\d{2})-(\d{4})$", "$3-$2-$1") AS s_rDate
```