1

I have tried to change the value of selection in angular material date picker to YYYY-MM-DD format as follows:

  1. In dateInput event of the field I call a function which will change the format of date using date pipe and set value back. However, the format doesnt change.

HTML Code

<input matInput placeholder="Stop Date" [matDatepicker]="stopDate" (dateInput)="OnStopDate($event.value)" formControlName="stopDate">
<mat-datepicker-toggle matSuffix [for]="stopDate"></mat-datepicker-toggle>
<mat-datepicker #stopDate></mat-datepicker>`

TS Code

`OnStopDate(Value){
   const update= this.datepipe.transform(Value, 'YYYY-MM-dd');  //this value is being update
   this.myForm.controls.stopDate.setValue(update,{emitEvent: false});    // the value is not being set in yyyy-mm-dd but in mm-dd-yyyy
 }

I did see a solution provided using MomentDateAdapter as here. Is this the only solution proceed and why ?

Ajanyan Pradeep
  • 1,097
  • 1
  • 16
  • 26
Jinxed
  • 738
  • 7
  • 27

0 Answers0