I am testing the ionic V7 ion-datetime I am able to bind the (ionChange) to an [(ngModel)] and format the change. What I am trying to do is link the ion-datetime-button to an [(ngModel)] and format to YYYY-MM-DD. is this possible.
html
<ion-datetime-button datetime="TESTID"></ion-datetime-button>
<ion-modal [keepContentsMounted]="true">
<ng-template>
<ion-datetime
#popoverDateMain
[showDefaultButtons]="true"
id="TESTID"
presentation="date"
displayFormat="YYYY-MM-DD" // Does nothing
min="{{minDateAvailable}}"
max="{{today}}"
(ionChange)="item.Input = formatDate(popoverDateMain.value)" // links to [(ngModel)]
>
</ion-datetime>
ts
import { format, parseISO } from 'date-fns';
formatDate(value: any) { return format(parseISO(value), 'yyyy-MM-dd'); }
getToday() {
this.today = this.formatDate(new Date().toISOString())
return this.today;
}
minDate(){
this.min = new Date();
this.min.setMonth( this.min.getMonth()-6)
this.min = this.min.toISOString();
this.minDateAvailable = this.formatDate(this.min);
return this.minDateAvailable;
}