19

I'm using this lib in my app:

https://reactdatepicker.com/

There is an excludeDates prop which I can use, where I can pass a list of dates aka this would exclude today and yesterday:

excludeDates={[moment(), moment().subtract(1, "days")]}

I would prefer to have a better way than passing however many hundreds of dates into that array though.

Thanks!

penguinsource
  • 1,120
  • 3
  • 16
  • 40

6 Answers6

36

Maybe you can use the component like that:

<DatePicker
  selected={this.state.startDate}
  onChange={this.handleChange}
  minDate={moment().toDate()}
  placeholderText="Select a day"
/>

You can use minDate and maxDate props to select a unique range of date selectable.

benjamin Rampon
  • 1,316
  • 11
  • 18
15
<DatePicker
selected={this.state.startDate}
onChange={this.handleChange}
minDate={new Date()}
/>

Things are little more simplified now. According to official https://reactdatepicker.com/

we can also use

  maxDate={addDays(new Date(), 5)} // 5 is number of days from today
Mbanda
  • 968
  • 11
  • 21
0

Use the following snippet in your code:

<DatePicker
    selected={new Date()}
    onChange={date => handleDateChange(date, field)}
    minDate={moment().toDate()}
/>
0

Use The Following according to the Documentation. This works for me. For https://github.com/henninghall/react-native-date-picker this Library.

<DatePicker
selected={new Date()}
onChange={date => dateOnChange(date, field)}
minimumdate={moment().toDate()} // Use minimumdate in Place of minDate. 
 // maximumDate= 'Customize it according to requirement' />
0

excludeDates property is not used for this case. It is used for unavailable dates. Let's say you have a booking hotel system and if a user wants to book a new room, you need to show unavailable dates on the date picker calendar. You need to fetch the database, find the booked days for the room and pass it to the exludeDates property

// this will disable the past days
minDate={new Date()}
Yilmaz
  • 35,338
  • 10
  • 157
  • 202
0

you can do something like this to disable past dates from being selectable:

<input type='date' min={new Date().toISOString().split('T')[0]} />
anilam
  • 694
  • 6
  • 7