Using Dataview with Calendarium Plugin

What I’m trying to do

I am trying to track characters ages based on the current date in the Calendarium plugin. Essentially, I was to have an Age: section in character info, and use a Dataview query to calculate the age of the character based on the current date in Calendarium.

Things I have tried

I am new to this and am not sure what to try, but I saw a similar problem solved by creating a Dataview field in the character note:
—-
Birthday: 1994-07-12
—-
And then calling it with:

Age::=date(today) - this.birthday

Which would display:

Age:: 31 years, 1 month, 2 days

This is almost exactly what I want, but instead of calling date(today) for the actual date, I want to call the current date set by the Calendarium plugin.

I was looking for the same thing, and in the end I was able to do something with deepseek (because I don’t understand it at all). Maybe it can help you or someone else.

dataviewjs
const calendarAPI = Calendarium.getAPI("Calendar Name");
const currentDate = calendarAPI?.getCurrentDate();

// I use filtering, for example, all my notes have an tag
const pages = dv.pages()
    .where(p => 
        p.birthday && 
        p.file && 
        p.file.tags && 
        (p.file.tags.includes("#character"))
    )
    .map(p => {
        const age = calculateAge(p.birthday);
        return {
            ...p,
            computedAge: age
        };
    })
    .sort(p => p.computedAge, 'asc');

dv.table(
    ["Character", "Birthday", "Age"],
    pages.map(p => {
        const [year, month, day] = p.birthday.split('-');
        return [
            p.file.link,
            `${day}.${month}.${year}`,
            p.computedAge
        ];
    })
);

// A function for displaying the month correctly (+1 to the month), because Dataview and Calendarium had a discrepancy
function getCorrectMonth(month) {
    return month + 1;
}

function calculateAge(birthDateStr) {
    if (!birthDateStr) return "Not specified";
    
    try {
        const [birthYear, birthMonth, birthDay] = birthDateStr.split('-').map(Number);
        const currentMonthCorrected = getCorrectMonth(currentDate.month);
        
        let age = currentDate.year - birthYear;
        
        if (currentMonthCorrected < birthMonth || 
            (currentMonthCorrected === birthMonth && currentDate.day < birthDay)) {
            age--;
        }
        
        return age;
    } catch (e) {
        return "Error";
    }
}

if (currentDate) {
    const correctedMonth = getCorrectMonth(currentDate.month);
    dv.paragraph(`*Current date: ${currentDate.day}.${correctedMonth}.${currentDate.year}*`);
}