calculate age in angular 7/8/9 using moment js.

Aman Sharma
0

 We can calculate age using moment js if we have date of birth as given below:

 
import * as moment from 'moment';


  /*Calculate Age*/

  public calculateAge(birthdate: any): number {
      return moment().diff(birthdate, 'years');
    }


/*check Age is less than 18 or not*/

if(this.calculateAge(this.frm.controls.dob.value)<18)
{
  this.showMessage('Please check DOB,Age is less than 18.','danger');
}
else
{
//do you code
}

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !