Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude future dates from a given date using React Datepicker

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?

like image 327
Liz Parody Avatar asked May 13 '18 20:05

Liz Parody


1 Answers

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"
/>
like image 73
Zohaib Ijaz Avatar answered Oct 05 '22 23:10

Zohaib Ijaz