Dataview broken countdown?

Hi everyone, basically I have a dataview table that counts number of days passed since 09 jan 2023, I use this query:

TABLE WITHOUT ID "Day "+ string(  date(file.cday).day+1 - date(2023-01-09).day) AS "Day",link(file.link)    as "Note"

And the result thus far worked:

Problem is that since February month is started I get this values:
image

Can someone help me identify the problem? Thank’s

You’re calculatiing only the difference in ‘day’, not considering ‘month/year’.
Maybe, the following code helps you.

TABLE WITHOUT ID "Day "+ string((date(file.cday) - date(2023-01-09)).days+1) AS “Day”,link(file.link) as “Note”

1 Like

Thank youuuu!!

Hello, sorry but the problem presented again… Here’s my snippet:

TABLE WITHOUT ID "Day "+ string((date(file.cday) - date(2023-01-09)).days+1) AS "Day",link(file.link)    as "Note" ,MMs AS "Goal",  MM as "Recap"
FROM "2 - Journaling/Daily Notes" 
WHERE MM and ((date(file.cday) - date(2023-01-09)).days)+1 <= 30
SORT file.ctime asc

Basically I want to be listed only day 1 to 30, as you can see day 29 is not being plotted:
image
If I change the snippet in:

WHERE MM and ((date(file.cday) - date(2023-01-09)).days)+1 <= 35

I get this
image
That’s of course completely wrong… Someone can help me solving this? Thank’s

Anyone?

I really don’t know for sure, but in my local tests (with ISO dates used as file names in my journal), file.cday gives imperfect results as not all the files were created on the dates they refer to. I get accurate results if I use file.day. It’s not clear to me if this is the issue you are facing, but thought I’d mention it just in case it is at all relevant … though your files don’t appear to be in ISO (YYYY-MM-DD) format, so probably spurious.

```dataview
TABLE WITHOUT ID 
	"Day "+ string((date(file.day) - date(2023-01-09)).days+1) AS Day,
	link(file.link) as Note
FROM 
	"journal/2023"
SORT 
	file.name ASC
LIMIT 
	10
```

At least my rambling post helps to bump the thread. :wink:

Hello, I make sure the file creation date is always equal to the date they’re referring to.

This is the date format I use on Dataview settings and for new daily note creation:

Thank’s for contribution. Is anyone able to solve this?

1 Like

I’m sorry to bother people but I really tried searching everywhere on the forum and on documentation, this is driving me crazy. Is really anyone there able to solve this easy issue?

Also, the problem persist if I try to use dataview inline:
=( date(2023-02-05) - date(2023-01-09)).days result in 27
=( date(2023-02-06) - date(2023-01-09)).days result in 30

There’s a 3 days gap out of nowere

Does this work in your vault?

- 5 Feb: `$=dv.array(moment('2023-02-05').diff(moment('2023-01-09'), 'days').toLocaleString('en-en') + " days")`   
- 6 Feb: `$=dv.array(moment('2023-02-06').diff(moment('2023-01-09'), 'days').toLocaleString('en-en') + " days")`
- 7 Feb: `$=dv.array(moment('2023-02-07').diff(moment('2023-01-09'), 'days').toLocaleString('en-en') + " days")`
- 14 Feb: `$=dv.array(moment('2023-02-14').diff(moment('2023-01-09'), 'days').toLocaleString('en-en') + " days")` 
- 21 Feb: `$=dv.array(moment('2023-02-21').diff(moment('2023-01-09'), 'days').toLocaleString('en-en') + " days")` 
- 28 Feb: `$=dv.array(moment('2023-02-28').diff(moment('2023-01-09'), 'days').toLocaleString('en-en') + " days")` 
- 1 Mar: `$=dv.array(moment('2023-03-01').diff(moment('2023-01-09'), 'days').toLocaleString('en-en') + " days")` 

Yes but that’s dataviewjs, I don’t know anything about it and it would require to rebuild everything from scratch

1 Like

There’s an open bug report about Dataview not being able to calculate dates correctly. Applies in your case?

1 Like

As you’ve most likely understood by now, there is a an issue when the duration extends beyond a month, and then it becomes buggy. One way around this, is to convert everything to a unix timestamps in seconds, and do a little bit of math.

```dataview
TABLE WITHOUT ID 
  dateformat(date(cday), "X"), 
  dateformat(date(2023-01-09), "X"), 
  (date(cday) - date(2023-01-09) ).days as OrgDays,
  dayCount
FLATTEN list("2023-02-03", "2023-02-04", "2023-02-05", "2023-02-06") as cday
FLATTEN
  ((number(dateformat(date(cday), "X")) - 
    number(dateformat(date(2023-01-09), "X")) ) / 86400) as dayCount
  WHERE file.name = this.file.name
```

The main thingy here is the last FLATTEN:

  • number( ... ) – Pulls out a number from a string
  • dateformat( ..., "X" ) – Format the date as a unix timestamp in seconds (aka seconds since 1970 or something like that)
  • Subtract these two values, and divide by 86400 which is the number of seconds in one day, and we get the dayCount between the two days

The other stuff in my query, is just to illustrate and test out the query. You’ll need to put back in file.cday instead of my cday (which I generated from a list), and adapt everything else to your situation. The key component though, is that last FLATTEN, which should be copy-paste (with the cday change), and then you can use dayCount in other parts of your query.

The query results in this output:

And here we can see both the faulty output using date calculations, and the correct output using calculations on the unix timestamps in seconds.

1 Like

You are a true saviour, thank you so much.

@anon63144152 Thank you too.

Hope this may help other people with the same problem until the bug is fixed.

2 Likes

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