Как рассчитать дату рождения по возрасту лет, месяцев и дней
<div class="col-md-12" *ngIf="!DOBKnown"> <div class="col-md-6"> <div class="form-group"> <label class="col-sm-3 control-label mandatory">Approx. Age</label> <div class="col-sm-3"> <input type="text" name='years' class="form-control" placeholder="Years" maxlength="3" (keyup)="checkYear($event.target.value)" formControlName="ageYears"> </div> <div class="col-sm-3"> <input type="text" name='months' class="form-control" placeholder="Months" (keyup)="checkMonth($event.target.value)" formControlName="ageMonths"> </div> <div class="col-sm-3"> <input type="text" name='days' class="form-control" placeholder="Days" (keyup)="checkDay($event.target.value)" formControlName="ageDays"> </div> </div> </div> <div class="col-md-6"> <div class="form-group"> <label class="col-sm-3 control-label"> Approx. Date Of Birth </label> <div class="col-sm-9"> <input type="date" class="form-control" (keyup)="calculate()" formControlName="dateOfBirth" [(ngModel)]="dobYear" disabled> </div> </div> </div> </div> createPatient() { this.createPatientForm = new FormGroup({ firstName: new FormControl('', <any>Validators.required), lastName: new FormControl('', <any>Validators.required), dateOfBirth: new FormControl('', <any>Validators.required), ageYears: new FormControl('', <any>Validators.required), ageMonths: new FormControl('', <any>Validators.required), ageDays: new FormControl('', <any>Validators.required), }); } **Patient create form**
Что я уже пробовал:
checkYear(year){ let mon = year.substring(0,(year.length-1)); if(year.length>0 && year.length<7){ if(year == 0){ year=mon; } else if(year < 1 || year>150){ year=''; } } else if(year.length>4){ year=mon; } } I tried to check the year.But I dint understand how to calculate month and day.If it is less than the current month and day.How will I give.