question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Durations always show "1 month" for 28/30/31 day differences

See original GitHub issue

What happened?

The table below is using a duration query to work out the amount of time elapsed since a specific start date: 2021-10-19

When parsed, the query says 15 November is 3 weeks and 6 days since the start date.

It then says that 16 November is 1 month since the start date.

It then says that 17 November is 1 month and 1 day since the start date.

It then says that 18 November is 1 month since the start date.

It then says that 19 November is also 1 month since the start date.

It then says that 20 November is 1 month and 1 day since the start date.

a52ee6627bba0d9982bac7587650145f043b7644

Am I doing something wrong or is this a bug?

Thanks

Angel

DQL

**Date** | **Duration**
:------------ | :------------
2021-11-15 | `=date(2021-11-15) - date(2021-10-19)`
2021-11-16 | `=date(2021-11-16) - date(2021-10-19)`
2021-11-17 | `=date(2021-11-17) - date(2021-10-19)`
2021-11-18 | `=date(2021-11-18) - date(2021-10-19)`
2021-11-19 | `=date(2021-11-19) - date(2021-10-19)`
2021-11-20 | `=date(2021-11-20) - date(2021-10-19)`

JS

No response

Dataview Version

0.4.21

Obsidian Version

0.12.19

OS

MacOS

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
blacksmithgucommented, Jan 21, 2022

I dug into this more and it turns out this is kind of complicated, but it’s because Luxon considers ‘28 days’, ‘30 days’ and ‘31 days’ to all be ‘1 month’; it also takes daylight savings time into consideration as well, which is a little annoying.

This seems like a very tricky fix; I underestimated how difficult durations are to work with! I’ll have to think on this a little more on how to make it ergonomic.

0reactions
AngelCherubcommented, Feb 10, 2022

I noticed today that a simple count of just days in isolation (no years, months, or weeks) leads to a miscalculation in DV. DVJS appears to get it right. Don’t know if this is related or helpful, but …

https://forum.obsidian.md/t/how-to-calculate-duration-between-dates-in-dataview/31225/14

Angel

Read more comments on GitHub >

github_iconTop Results From Across the Web

Month Calculator: Number of Months Between Dates - DQYDJ
The month calculator lets you enter two dates and we will give you the number of months (and days) between the two. Enter...
Read more >
Everything You Need to Know About Duration - EPMA Blog
If you enter a Duration value in elapsed Months, Microsoft Project always measures the elapsed month as exactly 30 calendar days. This means...
Read more >
Date Duration Calculator: Days Between Dates - Time and Date
The Duration Calculator calculates the number of days, months and years between two dates.
Read more >
MONTHS_BETWEEN scalar function - IBM
The MONTHS_BETWEEN function returns an estimate of the number of months between ... number difference based on the year and month values ignoring...
Read more >
calendarDuration - MathWorks
Use calendar duration arrays to simplify calculations on datetime arrays that involve calendar units, such as days and months. The datetime data type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found