0

I have a code bulog like this. works as I want. It cannot be selected 5 days before the current day. Now I want to do the same in the coming days. I don't want to choose days after 5 days .

example now : 10/05/2019 Days after 15.05.2019 cannot be selected. I want

const day = 5; const checkedDate = Datetime.moment().subtract(day, 'day');

Ali Bulut
  • 194
  • 1
  • 8
  • 1
    It sounds like you are probably wanting to _Add_ 5 days to the current day, and then compare any date selected to that, ensuring it is less than that. Here's an answer on how to add days https://stackoverflow.com/a/22547185/12290967 – Hanna Oct 30 '19 at 14:01
  • this helped me. Moment js isValidDate I needed a little review. – Ali Bulut Oct 31 '19 at 14:02

1 Answers1

0

this helped me. Moment js isValidDate I needed a little review. Example

   <Datetime
                        locale="tr"
                        value={request.travelEndDate}
                        isValidDate={this.checkDateIsValid}
                        dateFormat="DD-MM-YYYY"
                        timeFormat={false}
                        onChange={this.changeTravelEndDate}
                      />
   </div>


  checkDateIsValid(current) {
    const { configuration, request } = this.props;
    const { harcirahGeriyeDonukKontrolVarMi, harcirahGeriyeDonukGunSiniri } = configuration;
    if (harcirahGeriyeDonukKontrolVarMi) {
      const day = harcirahGeriyeDonukGunSiniri + 1;
   //   const day = 3;
      const nextDay = 5;
      const checkedDate = Datetime.moment().subtract(day, 'day')
      const checkedNextDate = Datetime.moment().add(nextDay, 'day')
      if(current.isAfter(checkedDate) === true){
       return current.isBefore(checkedNextDate);
      }
      return current.isAfter(checkedDate);
    }
    return true;
  }
Ali Bulut
  • 194
  • 1
  • 8