When using the React Datepicker library with Moment.js to manipulate dates, one can exclude given days as captured below and described in the React Datepicker documentation;
// Exclude today and yesterday.
excludeDates = {[moment(), moment().subtract(1, "days")]}
How can I exclude future dates from a given date?
You can use filterDate
check and return true if the date is in past.
The snippet below illustrates how to use filterDate
;
<DatePicker
selected = {this.state.date}
onChange = {this.handleChange}
filterDate = {(date) => {
return moment() > date;
}}
placeholderText = "Select a weekday"
/>
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