We will get new date
by adding month & date in given date. In previous article we learn how to change
date format using moment.js in angular8.click here
Component.html:
<mat-form-field color='accent'>
<input matInput [matDatepicker]="picker1" (click)="picker1.open()" placeholder="IssueDate" formControlName="issueDate" (dateChange)="getExpiryDate($event)" required>
<mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
<mat-datepicker touchUi #picker1></mat-datepicker>
</mat-form-field>
Component.ts:
// function to change date
getExpiryDate(event: any) {
let isueDate = event.target.value;
//Add Month to Issue Date
this.newDate = moment(new Date(this.form.controls. issueDate.value)).add(5,'M');
//Add days to Issue Date
this.newDate = moment(new Date(this.form.controls. issueDate.value)).add(15,'d');
}