obsidian-dataview icon indicating copy to clipboard operation
obsidian-dataview copied to clipboard

the Date calculation method might have some errors

Open Eplicony opened this issue 2 years ago • 3 comments

What happened?

image

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

Eplicony avatar Jun 22 '23 04:06 Eplicony

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"

GovSat1 avatar Aug 02 '23 15:08 GovSat1

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 .

bharker75 avatar Jan 19 '24 23:01 bharker75

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"

bharker75 avatar Jan 22 '24 15:01 bharker75