react-datepicker icon indicating copy to clipboard operation
react-datepicker copied to clipboard

How do we disable certain days of the week?

Open pagesrichie opened this issue 8 years ago • 6 comments

How do we disable certain days of the week?

Like for example, say I want to disable Monday and Tuesday. (Not just weekends)

pagesrichie avatar Jun 24 '18 02:06 pagesrichie

@pagesrichie https://reactdatepicker.com/#example-21

Fer0x avatar Jul 05 '18 08:07 Fer0x

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 30 '19 15:08 stale[bot]

You may use filterDate props. refer https://reactdatepicker.com/#example-filter-dates. also you need to use date.getDay() instead of getDay(date)

() => {
  const [startDate, setStartDate] = useState(null);
  const isWeekday = (date) => {
    const day = date.getDay();
    return day !== 0 && day !== 6;
  };

  return (
    <DatePicker
      selected={startDate}
      onChange={(date) => setStartDate(date)}
      filterDate={isWeekday}
      placeholderText="Select a weekday"
    />
  );
};

ahmadzt avatar Jun 02 '22 08:06 ahmadzt

thanks

BrayanTheloveend avatar Aug 18 '23 16:08 BrayanTheloveend

Is there a way to exclude the days from appearing in the calendar, i.e. only display Mon-Fri?

ashrafnazar avatar Jan 03 '24 16:01 ashrafnazar

Same question here, how can we exclude them and also hide them from the calendar?

tetaplaun avatar Mar 05 '25 07:03 tetaplaun