obsidian-dataview
obsidian-dataview copied to clipboard
the Date calculation method might have some errors
What happened?
Here we can see the date(today) is 6 22, the date of file "2023-5-24" is 5 24, but the day time interval between them is 31, making the table not an strictly increasing order.
I think there might be some errors in date calculation method or maybe some details I ignored.
DQL
table file.cday As Day, date(today), (date(today)-file.cday).day AS "Diff day", date(today)-file.cday AS values
from #📝
where true
OR (date(today)-file.cday).day = 1
OR (date(today)-file.cday).day = 3
OR (date(today)-file.cday).day = 5
OR (date(today)-file.cday).day = 9
OR (date(today)-file.cday).day = 16
OR (date(today)-file.cday).day = 29
OR (date(today)-file.cday).day = 60
OR (date(today)-file.cday).day = 100
OR (date(today)-file.cday).day = 200
OR (date(today)-file.cday).day = 365
sort file.cday DESC
JS
No response
Dataview Version
0.5.56
Obsidian Version
v1.3.5
OS
MacOS
This is a long-standing issue due to luxon date formats. As a workaround, you can convert to unix-time and divide.
Try: (( number(dateformat(date(today), "X")) - number(dateformat(date(file.cday), "X")) ) / 86400 ) AS "Diff Day"
As a workaround, you can convert to unix-time and divide. Try:
(( number(dateformat(date(today), "X")) - number(dateformat(date(file.cday), "X")) ) / 86400 ) AS "Diff Day"
I encountered this bug today and kept looking for ways to convert dates to something that would math properly and found your fix. Thanks for the workaround @GovSat1 .
A note that if the dates cross daylight savings you'll end up with fractions so adding a round(,0) is the easy fix:
round((( number(dateformat(date(today), "X")) - number(dateformat(date(file.cday), "X")) ) / 86400 ),0) AS "Diff Day"