javascript - How to get age from date string using angular 2 -
i have check age validation, have tried following method getting age:
let newdate = new date(this.userdob); var timediff = math.abs(date.now() - newdate); let age = math.floor((timediff / (1000 * 3600 * 24)) / 365);
here this.userdob string. how can use string age using javascript?
i have done using this,
var dob = //here im getting dob var today = new date(); var birthdate = new date(dob); var age = today.getfullyear() - birthdate.getfullyear(); var m = today.getmonth() - birthdate.getmonth(); if (m < 0 || (m === 0 && today.getdate() < birthdate.getdate())) { age--; }
now i'm able check age
Comments
Post a Comment