0👍
import * as moment from "moment";
let birthday = moment(moment.now()).diff(moment(this.user.day + this.user.month + this.user.year, "DD.MM.YYYY"),"years");
if(birthday > 21 && birthday < 55) {
// do next steps
}
Moment(npm install moment
) is used to parse, manipulate & display dates and times in JavaScript. moment.now()
will give the present date and assuming you have three fields for day
, month
and year
in different variables, format it and use the diff
function to find the age.
- [Vuejs]-Using Axios and Vue.js to load JSON data
- [Vuejs]-How to cherry publish my components library?
0👍
The example from Madhuri works for me but i change the input as hard coded string.
enter code here let birthday = moment(moment.now()).diff(moment('01.01.1990', "DD.MM.YYYY"), "years");
if(birthday >= 20 && birthday <=70 ){
return birthday;
}
}
- [Vuejs]-Onload page on Vue for showing spinner / loader gif?
- [Vuejs]-V-show on v-for creates unwanted return transition
0👍
I solved it with with value from form input which works for me.
checkBirthday(){
const birthDayDate = document.getElementById("birthdate").value;
const age = moment().diff(birthDayDate, "years");
// let birthday = moment(moment.now()).diff(moment('01.01.1990', "DD.MM.YYYY"), "years");
if(age >= 18 && age <=74 ){
return age;
}
},
Source:stackexchange.com