Hiya, I’m trying to list the age of different people using Dataview.
I use a simple calculation to determine the age -
TABLE WITHOUT ID Name, BirthDate AS "Born",
date(today) - BirthDate AS Age
WHERE Name
This works when there is one person, but fails when there is more than one:
Note: Their info is stored as -
Name:: Bob Bobly
BirthDate:: 2001-01-01
Name:: Sam Samly
BirthDate:: 1999-09-09
This is the error I’m getting -
Dataview: Every row during final data extraction failed with an error; first 3:
- No implementation found for 'date - array'
Things I have tried
I tried quite a few different ways of addressing this, and stripped out everything extraneous to test the problem, but I think there may be something fundamental I’m missing or misunderstanding. My usage of DataView is fairly basic, but mostly successful so far.
0.To require the note structure like case_DVIF_DDD 1.To require the field YAML_today: 2022-09-10 in the current note 2.To deal with lists or non-lists 3.To filter by BirthDate 4.To sort by file.link in ascending order 5.To display the result as a table
1.To require the field YAML_today: 2022-09-10 in the current note
2.You could replace this.YAML_today in the DQL with date(today) if you would not like to use the field YAML_today.
title: DQL10_map_lists_non-lists_durations_and_TABLE =>0.To require the note structure like case_DVIF_DDD 1.To require the field `YAML_today: 2022-09-10` in the current note 2.To deal with lists or non-lists 3.To filter by BirthDate 4.To sort by file.link in ascending order 5.To display the result as a table
collapse: close
icon:
color:
```dataview
TABLE WITHOUT ID
file.link AS "File",
Name AS "Name",
map(
choice(typeof(BirthDate) = "array", BirthDate, list(BirthDate)),
(e) => dateformat(e, "yyyy-MM-dd")
) AS "Born",
map(
choice(typeof(BirthDate) = "array", BirthDate, list(BirthDate)),
(e) => round(dur(this.YAML_today - e).years - 0.5, 0)
) AS "Age"
FROM "100_Project/02_dataview/Q89_BirthDate/Q89_test_data" AND #person
WHERE BirthDate != null
SORT file.link ASC
```
@justdoitcc: no one can understand whatever you trying to present.
@natex Let assume you have a folder called “PEOPLE”, contain person 1.md note that have the tag #people AND person 2.md note that also have the tag #people
AND on top of those notes you have a birthday and phone data in YALM frontmatter like this
Install another plugin called “Sortable” to sort that table in whatever you want by clicking on the column header.
More trick: you can have 3 table like this, one for family, one for coworker, one for friend … or whatever by tag each person note difference like #people/family#people/coworker#people/friend, THEN edit the tag in begining part of the code according to those group of people.
Now the dataviewjs gonna look like this :
```dataviewjs
// People birthdays using DataviewJS
let pages = dv.pages("#people").where(p => p.birthday);
var start = moment().startOf('day');
var end = moment(start).add(dv.current().duration);
var dateformat = "YYYY-MM-DD"
function nextBirthday(birthday) {
var bday = moment(birthday.toString());
var bdayNext = moment(bday).year(start.year());
if (bdayNext.isBefore(start, 'day')) {
bdayNext.add(1, "year");
}
return bdayNext;
}
function countdown(birthday){
var bday = moment(birthday.toString())
const setTime = new Date(bday);
const nowTime = new Date();
const restSec = setTime.getTime() - nowTime.getTime();
const day = parseInt(restSec / (60*60*24*1000));
const str = day + " days";
return str;
}
dv.table(["Name", "Birthday", "Age","Countdown", "Phone"],
pages.sort(p => moment(p.birthday.toString()).format("MM-DD"), 'asc')
.sort (p => p.birthday, 'desc')
.map(p => [
// The name
p.file.link,
// Formatted birthday from YAML frontmatter
moment(p.birthday.toString()).format("MMMM Do"),
// Current age in years
moment().diff(moment(p.birthday.toString()), 'years'),
countdown(nextBirthday(p.birthday)),
p.phone,
]
)
);