Ion Datetime default

Hi !
I would like to put a date by default in my Ion Datetime.
The problem is when I put a date with ngModel I loose the placeholder so How Can I put a date by default ? for example, When the user focus the datetime, the date is on 15 december 1996 and no the current date ?

Thanks,
Vincent

Hi, @Quiesan

Try this:

.ts

myDate:string;

ionViewDidLoad() {
	this.myDate = new Date('1996-12-15T02:00:00Z').toISOString();
}

.html

<ion-item>
  <ion-label>Date</ion-label>
  <ion-datetime displayFormat="DD/MM/YYYY" [(ngModel)]="myDate"></ion-datetime>
</ion-item>

Thank you.

Thanks for your answer but we this method I lost my placeholder… I just want this date when the user tap on the ion datetime but before I would like the placeholder

Hi, @Quiesan

Add this code, it is working fine as per your requirement,

.ts

myDate:string;

click(myDate){
      if (myDate == undefined || myDate == null) {
        this.myDate = new Date('1996-12-15T02:00:00Z').toISOString();
        console.log('if date',this.myDate);
      }else{
        console.log('else date',this.myDate);
      }
}

.html

<ion-item>
	 <ion-label>Date</ion-label>
	 <ion-datetime placeholder="tap here to enter Date" (click)="click(myDate)" displayFormat="DD/MM/YYYY" [(ngModel)]="myDate"></ion-datetime>
</ion-item>

Thank you.

I already try this method but there is one problem ! The date is ok but the switch for the date is on the today date and no on the new date…

Someone have an idea please ?

No idea …? :frowning: