Search code examples
ionic-frameworkionic4

How to set minimum and max times in an ion-datetime


I am using an ionic DateTime component to pick just time in my page. But I have to just allow the user to select times from 06:30 Am to 07:30 PM. How can I limit the min-max times in ion-datetime

I have already tried giving min value to the component directly.

<ion-datetime displayFormat="hh:mm a" min="minDate"></ion-datetime>


Solution

  • you can specify them as props:

    <ion-item>
      <ion-label>Date</ion-label>
      <ion-datetime displayFormat="MMMM YYYY" min="2016" max="2020-10-31" [(ngModel)]="myDate">
      </ion-datetime>
    </ion-item>
    

    check the ion-datetime docs on Min and Max Datetimes section