I'm using calendar input as follows.
<p-calendar maxDate="dateTime" showTime="true" hourFormat="12" showButtonBar="true" [(ngModel)]="dateTime" name="timeOfUse" required #timeOfUse="ngModel">
</p-calendar>
I want to disable future dates in this datepicker. It may be a simple property, but I can't figure it out. Appreciate any help
How do I restrict future dates in Datepicker? To disable future dates in JQuery date picker, we need to set the maxDate property. maxDate : 0 then all the future dates will be disabled. maxDate : '+1w' then all the future dates after a week will be disabled.
To disable past and future dates, we can use min and max properties in Datepicker input text with matInput attribute. If only past dates need to be disabled, configure only min property. If only future dates need to disabled, configure only max property.
daterangepicker({ autoUpdateInput: false, locale: { cancelLabel: 'Clear', format: 'DD-MM-YY' } });
To disable specific dates and/or dates first set the readonlyInput to true so that the user cannot enter the dates using the keyboard. Now disable the dates using the disabledDates property and/or disable days using the disabledDays property.
You're not so far ! Just add square brackets to maxDate
and it will work :
<p-calendar [maxDate]="dateTime" showTime="true" hourFormat="12" showButtonBar="true" [(ngModel)]="dateTime" name="timeOfUse" required #timeOfUse="ngModel">
</p-calendar>
And if you want to disable dates 3 days after today for instance :
export class AppComponent {
dateTime = new Date();
constructor() {
this.dateTime.setDate(this.dateTime.getDate() + 3);
}
}
Found this on web might help you,Read the topic Disable specific dates and/or days
Date Restriction
[maxDate]="maxDateValue"
https://www.primefaces.org/primeng/#/calendar
Reference
https://forum.primefaces.org/viewtopic.php?f=35&t=49578
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With