I am building a family tree in Obsidian and would like to show the age of every family member with dataview. However, I found no solution to calculate dates.
Name: Peter Doe
Born: 1854-7-24
Died: 1942-3-13
Age:
TABLE
Born, Died, Age
FROM #person
SORT Name DESC
Any suggestion on how to show the age dynamically?
Angelâs answer will work using just dataview, if you donât want to go down the Javascript path.
One thing to note however, if the person does not have a recorded date of death, then that person will not be listed in the table. Not knowing how all the files are set up, this might not be a problem. If there are people who are still living, you could calculate the age with something similar to the following in your dataview query:
choice(!Death, date(today), Death) - Birth as Age
This says if there is no value for Death replace it with the current date.
Screenshot of original post, and the updated view taking living persons into account:
At @anon12638239 there are separate pages for each person. As mnvwvnm states, if you have the same key multiple times in a single document then you will turn the values into an array and you would have to deal with this those in a different way. I donât know if dataview would let you properly flatten multiple arrays properly, although it might be easily done with dataviewjs. In that case you would need to make sure the data is correctly entered so perons 1âs name/dates all aligned.
Since the OP is building a family tree I would assume that each person had their own page that would contain interesting facts about the personâs life.
I had assumed I could keep multiple peopleâs data in one set of YAML (similar to the employee records in this link) and then draw out the data using Dataview. My bad.
I am working on a version of this for my own needs.
I would like âTimeâ to be in days only, rather than years, months, weeks, and days.
Is that possible?
```dataview
TABLE WITHOUT ID
file.link AS What,
choice(!DatesEnd, date(today), DatesEnd) - DatesStart as Time
FROM #obsidian
WHERE DatesID
SORT DatesStart ASC
```
If I use both DV and JS to calculate the number of days between two dates, they give different amounts (see the sample file attached). I know there is an issue with how dates are calculated in DV, but I thought that would be when calculating years / months / weeks / days. Assumed that a count of just days would be the same, but it seems not.
Well, JS isnât my groundâŚ
About DQL queries, it seems that the date calculations arenât very rigorous (because it fails in the number of days per month).
If you want to add the word âdaysâ you can write (choice(!DatesEnd, date(today), DatesEnd) - DatesStart).days + " days" AS Time.
About how to format the output in similar way as toLocaleString() I really donât know how to do it. Thereâs no similar function as format() in sql.
At the moment, I will stick with your brilliant JS solution at it produces a completely accurate calculation.
The DV query is out by a varying number of days in every test I have done, so keeping the JS solution at least means I have reliable data.
I was looking to switch as DV renders in live preview, but JS only works in reading mode.
I am trying to adjust to the new editor, knowing the old one will be deprecated in time. Thing I miss most is being able to see whitespace / invisibles. The old CSS and plugin solutions donât work at the moment, and I have had no success when trying to create suitable CSS snippets for CM6.