Search code examples
dateneo4jcypher

how can i get age from date of birth in neo4j


I´m starting with neo4j and would like to know how to get the age in years. I have the node below

(p1:Person{id:1,birthdate:"1989-10-03",name:"Person1"})

tried something like this

with p.birthdate as bd, date() as d return d - bd

Solution

  • You can use date and duration types, for instance like this:

    MATCH (p:Person {name: "Person1"})
    WITH duration.between(date(p.birthdate), date()) as d
    RETURN d, d.years, d.months, d.days