Answer the question
In order to leave comments, you need to log in
In what time period should you look for people who are now X years old?
I have a little problem with the presentation of data in my head, so I'm writing here.
How to find all people who are now X years old? The age in the database is stored as the date of birth in ISO format.
I need to make a query to find all the people who are now some years old, let's say 16.
What is the lower date limit and what is the upper date limit?
Can January 1, 2005 be considered the lower limit, or can there be people who were born in 2004 but are still 16 years old?
Then the upper limit is December 31, 2005? or does it not cover all possible sixteen year olds? Or vice versa, will 17-year-olds also get into the issue?
Then it turns out something like this:
people.find({
age: {$gte: new Date(new Date().getFullYear() - age, 0, 1), $lt: new Date(2005, 11, 31)}
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question