I’m using Obsidian to track characters and plots and I thought it would be useful to have a table with characters’ ages inside each plot note. That was easy to achieve except I didn’t want the ages displayed as “years months days” and I ddin’t want them rounded up either.
Since dataview doesn’t round down I came up with a solution that I thought could be useful to somebody else too.
Field HappenedOn is in the plot note, field Birthday is in each character’s note.
truncate(string((this.HappenedOn - Birthday)),2,"")
I don’t expect numbers with more than two digits but if you do, just change the 2 to something else.
Below is the full code I use to have a table that tells me the characters’ ages, if there’s no data for them, if they are deceased or if they weren’t born yet at the point in time when the plot action happened. I’m using call outs to make certain elements pop out.
Hope some of it is useful to another Obsidian user.
TABLE choice( Deceased=null AND Birthday=null, "_N/A_", choice( Deceased!=null AND Deceased <= this.HappenedOn, "> [!danger] Deceased", choice( Birthday!=null AND Birthday <= this.HappenedOn, choice( Birthday = this.HappenedOn, "> [!done] It's TODAY!!", truncate(string((this.HappenedOn - Birthday)),2,"") ), "> [!info] Not born yet" ) ) ) AS Age FROM "Characters" SORT file.name asc