Search code examples
datepickerantd

How to enable only 3 months in AntD Range Picker?


I am using AntD Range Picker. I want to allow the user to select only 90 days, starting from 90 days from today. I have mange to block all the future days (after today) with the following code. How can I allow only 3 months (3 months back from today)?

<RangePicker
            format="YYYY-MM-DD"
            onChange={onChange}
            disabled={loading}
            onOpenChange={onOpenChange}
            disabledDate={(currentDate) => currentDate.isAfter(moment())}
          />

Solution

  • Try this:

    function disabledDate(current) {  
        return current > moment() || current < moment().subtract(3, 'day');
    }
    
    <DatePicker disabledDate={disabledDate} />
    

    the first condition will disable the future days and the second one will enable 3 dates backward from today. In your case, you can change it to 90.

    Edit