Ionic datepicker how to preset a date inside FormBuilder

Hello
i am using a datepicker like so inside a FormBuilder

 <ion-item>
        <ion-label>Event Start Date</ion-label>
        <ion-datetime displayFormat="MM/DD/YY" formControlName="startDate"  [ngClass]="{'has-error':!newEventForm.controls['startDate'].valid}"></ion-datetime>
      </ion-item>
      <ion-item>
        <ion-label>Event End Date</ion-label>
        <ion-datetime displayFormat="MM/DD/YYYY" formControlName="endDate" [ngClass]="{'has-error':!newEventForm.controls['endDate'].valid}"></ion-datetime>
      </ion-item>

i have tried below but not working



    this.newEventForm.controls["startDate"].setValue(Date.now());

How do i preset the date so the user does not need to move it alot

this in init worked for me


    var today = new Date();
    var dateVal = today.getFullYear().toString() + '-' + (today.getMonth() + 1).toString() + '-' + today.getDate().toString();      
        
    
    this.newEventForm.controls["startDate"].setValue(dateVal);
    
    this.newEventForm.controls["endDate"].setValue(dateVal);
    
1 Like