title: Getting days difference between two dates in React.js
body: <p>I'm working with <strong>date picker in react</strong> and have implemented Start and end date which works fine. now I need to get 
  the days difference  between the two dates(between Start and End dates).</p>
  
  <p>Here is the problem. Each time I select the two dates to get the difference in days, it only shows the initialize 0 days.
  I have resorted to a solution <a href="https://stackoverflow.com/questions/49844164/react-datepicker">here</a></p>
  
  <p>But still, show <strong>0 days</strong> on date select element. No error message is shown on the console.</p>
  
  <p><strong>Here is my code</strong></p>
  
  <pre><code>//install the following
  //npm i --save react-datepicker
  //npm i --save moment
  
  import React from "react";
  import DatePicker from "react-datepicker";
  
  import "react-datepicker/dist/react-datepicker.css";
  
  
  class CheckDate extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        startDate: new Date(),
        endDate: new Date(),
        days: 0,
      };
      this.handleChangeEnd = this.handleChangeEnd.bind(this);
      this.handleChangeStart = this.handleChangeStart.bind(this);
      this.daysLeft = this.daysLeft.bind(this);
  
    }
  
    handleChangeStart(date) {
      this.setState({
        startDate: date
      });
    }
  
  
   handleChangeEnd(date) {
      this.setState({
        endDate: date
      });
    }
  
  
  daysLeft() {
      let {startDate, endDate} = this.state;
      console.log(startDate);
      console.log(endDate);
      let amount = endDate.diff(startDate, 'days');
      this.setState({
        days: amount
      });
    }
  
  
  
    render() {
      return (
       &lt;div&gt;
            &lt;h3&gt;Get Difference between two dates in days&lt;/h3&gt;
  
  &lt;b&gt;Start Date&lt;/b&gt;:
   &lt;DatePicker
     selected={this.state.startDate}
     onChange={this.handleChangeStart}
   /&gt;
  
  &amp;nbsp;&amp;nbsp;&amp;nbsp;
  
  &lt;b&gt;End Date&lt;/b&gt;:
   &lt;DatePicker
     selected={this.state.endDate}
     onChange={this.handleChangeEnd}
   /&gt;
  
   &lt;div className="amount"&gt;
     {this.state.days}
   &lt;/div&gt;
  
  &lt;/div&gt;
      );
    }
  }
  </code></pre>