user944513
user944513

Reputation: 12729

How to disable current month date and furture date in JavaScript?

How to disable current month date and future date in JavaScript? here is my code https://codesandbox.io/s/condescending-ptolemy-rj3lc

As current month is jan so I want to disable jan-2020 to all future dates Feb-2020 ...dec-2020

<DatePicker
      onChange={onChange}
      disabledDate={current => {
        console.log(moment().month());
        console.log(current.month());

        return moment().month() >= current.month();
      }}
    />

Upvotes: 0

Views: 462

Answers (1)

rafaelncarvalho
rafaelncarvalho

Reputation: 729

You can use the isSameOrAfter of moment

<DatePicker
  onChange={onChange}
  disabledDate={current => current.isSameOrAfter(moment(), 'month')}
/>

Docs: https://momentjs.com/docs/#/query/is-same-or-after/

Upvotes: 2

Related Questions