0

I am using react-datepicker. Here is the docs link.

I have two input box for dates.One is for "Starting date" and another is for "ending date". what i need is end date is not less than the starting date.

I am running the below code which is not working fine.

 handleEndingDateChange(date) {
if(this.state.startingDate){
  if(this.state.startingDate<date){
    console.log('deadline date should be greater than starting date.')
    this.setState({
      deadLineError:(!this.state.deadLineError),
      endingDate: date
    })
  }else{
    console.log('date ok!');
    this.setState({
      deadLineError:(!this.state.deadLineError),
      endingDate: date,
    });
  }      
}
}

Can anyone please help me to solve this issue.

You Nguyen
  • 9,961
  • 4
  • 26
  • 52

1 Answers1

1

Try:

if (startDate.getTime() <= endDate.getTime()) {
  ...
} else {
  ...
}
Yossi
  • 5,577
  • 7
  • 41
  • 76