Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date calculations in tables - possible new content #50

Open
claremacrae opened this issue Jan 19, 2025 · 2 comments
Open

Date calculations in tables - possible new content #50

claremacrae opened this issue Jan 19, 2025 · 2 comments

Comments

@claremacrae
Copy link
Contributor

Hi, firstly thank you for this amazing resource.

I recently wanted to add a dataview table column with a value calculated from a date in each file's frontmatter property.

If the info is in this project, I was unable to find it.

So I'm sharing here what I learned on Discord, in case it is new info and anyone has time to integrate the example in to this sample vault....

Date calculations in columns

User dryice9290 on Discord shared the following, which I combined with the column alignment code you already have here:

This uses the date property value account-last-balanced-on...

```dataview
TABLE
    account-last-balanced-on,
    dateformat(account-last-balanced-on, "dd MMM yyyy") AS "dd MMM yyyy",
    date(today) - (account-last-balanced-on) AS "time since last balance",
    "<span style='display:flex; justify-content: right;'>" + (date(today) - (account-last-balanced-on)).days + " days" + "</span>" AS "time since balanced",
    round((date(today) - account-last-balanced-on).months, 0) + " months" AS "months since last balance",
    round((date(today) - account-last-balanced-on).years,  2) + " years"  AS "years since last balance"

FROM #account

SORT account-last-balanced-on ASC
```

This works well even when there is no date value, as the first two rows here show:

Image

Looking at it now, I could have right-justified more columns, but it's time to stop fiddling and save this!

@s-blu
Copy link
Owner

s-blu commented Jan 19, 2025

Hey Clare, thanks alot for sharing! You're writing

, which I combined with the column alignment code you already have here:

There's no link after the colons, but I believe you mean the page about styling dataview tables?

As far as I can see, there's no decent page for date based calculations yet (I thought there were one, though, maybe the search is failing me right now), so it'd be certainly a nice addition to the vault. :)

@claremacrae
Copy link
Contributor Author

Yes, that was the intended link - thanks for noting it.

I hope someone who knows the structure here can find time to add this...

Sorry I can't offer to do that - I'm feeling swamped by the demands of other Obsidian-related responsibilities for the foreseeable future. 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants