I am using following to calculate age in timestamp difference.
db.getCollection('person').aggregate( [
{ $project: {
item: 1,
DOB: "$personal.DOB",
dateDifference: { $subtract: [ new Date(), "$personal.DOB" ] }
} }
] )
I get the numeric value in dateDifference
. I want to convert it to years by dividing it with (365*24*60*60*1000). But I don't know how to specify this formula in above query. I have tried the following, but it does not return any value
db.getCollection('person').aggregate( [
{ $project: {
item: 1,
DOB:"$personal.DOB",
dateDifference: ({ $subtract: [ new Date(), "$personal.DOB" ] })/(365*24*60*60*1000)
} }
] )