Dataview Date / Age Table Issues - Multiples Don't Work - How To Fix?

What I’m trying to do

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.

Thanks for any help you can give.

Topic

Summary
  • How to calculate the ages of the persons?

case_DVIF_DDD: use different DVIFs which are repeated in a file
DVIF: use DVIF
DDD: three different DVIFs (for example)

Take the following file as an example.

---
Date: 2001-04-01
---
#person

Name:: Jason Statham
BirthDate:: 1967-07-26

Name:: Vin Diesel
BirthDate:: 1967-07-18


Test

Summary
  • dataview: v0.5.46

Input

Summary

the current note

  • filename : 20220910_DQL10
---
YAML_today: 2022-09-10
---

### DQL10


dictionary files

  • Location: “100_Project/02_dataview/Q89_BirthDate/Q89_test_data”

  • filename : dic_20010301
---
Date: 2001-03-01
---
#person

Name:: Dwayne Johnson
BirthDate:: 1972-05-02


  • filename : dic_20010401
---
Date: 2001-04-01
---
#person

Name:: Jason Statham
BirthDate:: 1967-07-26

Name:: Vin Diesel
BirthDate:: 1967-07-18


  • filename : dic_20010501
---
Date: 2001-05-01
---
#person

Name:: Gal Gadot
BirthDate:: 1985-04-30

Name:: Anne Hathaway
BirthDate:: 1982-11-12

Name:: Emma Watson
BirthDate:: 1990-04-15


  • filename : dic_20010601
---
Date: 2001-06-01
---
#person

Name:: 
BirthDate:: 


DQL10_map_lists_non-lists_durations_and_TABLE: case_DVIF_DDD

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL10_map_Lists_notLists
_duration_and_TABLE
BirthDate:
lists or non-lists
no 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.

code DQL10_map_lists_non-lists_durations_and_TABLE: case_DVIF_DDD

Summary_code
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

```

Screenshots(DQL10)

this.YAML_today: 2022-09-10


@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

birthday: 2000-12-01
phone: 0123456789

SCREENSHOT

  • 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,
	]
  )
);
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.