I'm using luxon.js and want to check, is the user's age is over than 21 years. Code, that i'm using for it
const isTooYoung = date =>
DateTime.fromFormat(date, 'dd.MM.yyyy')
.diffNow()
.as('years') < -21;
But for todays' s day (18.11.2019) both calls:
console.log(isTooYoung('15.11.1998')); // true => incorrect
console.log(isTooYoung('20.11.1998')); // true => correct, this user is not 21 year old yet
fiddle: http://jsfiddle.net/zh4ub62j/1/
So, what is correct way to solve problem to check, is the user's age is over than x years?