Dataview's date.week function possibly bugged

Things I have tried

What I’m trying to do

I was trying to create a list of every file I created this week using dataview when I noticed something weird:

Today is January 21st, so I expected that the result from date(2023-01-21T21:00).week would be 3, but it is 4.

I tested this with each day of the month like this:
`= date(2023-01-01T21:00).week`
`= date(2023-01-02T21:00).week`
`= date(2023-01-03T21:00).week`

And noticed that the first week only had 6 days.

`= date(2023-01-06T12:00).week` → gives week 1

`= date(2023-01-07T12:00).week` → gives week 2

So week 1 is considered to be from 2023-01-01 to 2023-01-06, which is 6 days.

Am I missing something here or is it bugged?

Moved this to #get-help as plugin bug reports go on the plugin’s GitHub repository, though someone else here might have insight into this behavior.

1 Like

So, I don’t know. I’ve never used this.

But expand your tests, because I think something even more funky is going on.

I removed the time just to experiment

`= date(2023-01-06).week` = 1
`= date(2023-01-07).week` = 2 (so far the same as you)
`= date(2023-07-12).week` = 2 (wat?)
`= date(2023-03-23).week` = 4
`= date(2023-02-01).week` = 1
`= date(2023-11-20).week` = 3

But I don’t know where to find the documentation for the syntax. So I don’t know if this is a dv week parsing bug, or a mismatched syntax. Or if it’s just returning the week of the current month of the date object (I don’t think so. 2023-11-20 should be 4 in that case, I think).

(In either case, I do see the off-by-one like you.)

1 Like

From this post, ‘Just realised the date.week is week of the month and not calendar week’.

And from this reference:

You can retrieve various components of a date via indexing: date.year, date.month,, date.hour, date.minute, date.second, date.week, date.weekyear.

It seems that date.weekyear should be used. Yes? Correlates with the week numbers given in the calendar.

Copy and ‘paste and match style / paste as plain text’ the text below into a note to test.

1. ==`= date(2023-01-01).weekyear`==
2. ==`= date(2023-01-02).weekyear`== 
3. `= date(2023-01-03).weekyear` 
4. `= date(2023-01-04).weekyear` 
5. `= date(2023-01-05).weekyear` 
6. `= date(2023-01-06).weekyear` 
7. `= date(2023-01-07).weekyear`
8. `= date(2023-01-08).weekyear`
9. ==`= date(2023-01-09).weekyear`==
10. `= date(2023-01-10).weekyear`
11. `= date(2023-01-11).weekyear`
12. `= date(2023-01-12).weekyear`
13. `= date(2023-01-13).weekyear`
14. `= date(2023-01-14).weekyear`
15. `= date(2023-01-15).weekyear`
16. ==`= date(2023-01-16).weekyear`==
17. `= date(2023-01-17).weekyear`
18. `= date(2023-01-18).weekyear`
19. `= date(2023-01-19).weekyear`
20. `= date(2023-01-20).weekyear`
21. `= date(2023-01-21).weekyear`
22. `= date(2023-01-22).weekyear`
23. ==`= date(2023-01-23).weekyear`==


Yeah, date.weekyear works for what I wanted. It was just hard for me to understand why the week started on Monday because I always saw on calendars it starting on Sundays, and I didn’t find much documentation about these week.<function>, so it is hard to understand what the return value will be.

Thank you!

1 Like

Welcome. I didn’t really know what I was doing but got lucky with a bit of searching and reading. Useful insight for me. Glad it is working for you.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.