1

I only want to disable the days of the week that I choose, or otherwise enable the days that I need

here is an illustrative image

here is an illustrative image

I found this code in the documentation but it doesn't work for me

    () => {
  const [startDate, setStartDate] = useState(null);
  const isWeekday = (date) => {
    const day = getDay(date);
    return day !== 0 && day !== 6;
  };
  return (
    <DatePicker
      selected={startDate}
      onChange={(date) => setStartDate(date)}
      filterDate={isWeekday}
      placeholderText="Select a weekday"
    />
  );
};

1 Answers1

1

You can change the day of the week to disable in this example from the docs on the line return day !== 0 && day !== 6; by changing the last number.

For instance, changing day !== 6 to day !== 7 will exclude only Sundays, etc.

If you want to exclude multiple days of the week, add && day !== [day number] to the callback. For instance day !== 0 && day !== 2 && day !== 5; will exclude Sundays, Tuesdays & Fridays.