I want to disable previous dates and all Saturdays and Sundays in Datepicker. How can I do that?
<input class="col-lg-3" type="date" min="{{ minimumDate}}" id="form3Example1cg" placeholder="Date" formControlName="date" class="form-control form-control-lg" />
minimumDate = new Date().toISOString().split('T')[0];
To disable all previous dates, set the [min]
attribute to the current date
, and to disable the weekends, you can use [attr.disabled]
and check if the day
of the date
is Sunday or Monday
<input class="col-lg-3 form-control form-control-lg"
type="date"
[min]="currentDate"
[attr.disabled]="isWeekend(date) ? '' : null"
id="form3Example1cg"
placeholder="Date"
formControlName="date">
Define the isWeekend
function.
isWeekend(date: Date): boolean {
const day = date.getDay();
return day === 0 || day === 6; // 0 = Sunday, 6 = Saturday
}