skp
skp

Reputation: 43

Limiting the npm react-date-picker to show only last 30 days from today dynamically in react

Show only last 30 days from today in npm react-date-picker dynamically in react. Future dates from tomorrow should be disabled.

import DatePicker from "react-date-picker";
<DatePicker maxDate={new Date()} />

Upvotes: 1

Views: 2401

Answers (3)

abdulalim
abdulalim

Reputation: 480

maxDate={new Date().setDate(new Date().getDate() + 90)}

Future date disable in react js. Here from today 90 days will be available for selecting

Upvotes: 1

Belaid BOUAOUALTEN
Belaid BOUAOUALTEN

Reputation: 391

you can use moment() and especially the function subtract() like in the exemple:

<DatePicker maxDate={new Date()}

 minDate={moment(new Date()).subtract(30, 'days')} />

Upvotes: 0

Dmitry S.
Dmitry S.

Reputation: 8503

What exactly is the question? You can create a date 30 days from now in JavaScript as follows:

var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 30);

Upvotes: 0

Related Questions