title: Convert date range object into ISO-8601 format using moment.js
body: <p>I am using <a href="https://github.com/Kiarash-Z/react-modern-calendar-datepicker" rel="nofollow noreferrer">this react based</a> date range picker. It gives me a <code>setSelectedDayRange</code> as an object of <code>from</code> and <code>to</code> like this</p>
  <pre><code>from: {day: 3, month: 8, year: 2020}
  to: {day: 8, month: 8, year: 2020}
  </code></pre>
  <p>I need to convert the above into the <code>ISO-8601 format</code>. Since I already have moment.js installed in my project, I was hoping to utilize it.</p>
  <p>The problem is</p>
  <ol>
  <li><p>if I try to do it like</p>
  <pre><code>    setSelectedDayRange = moment();
      let convertedDate = moment().toISOString();
      console.log(&quot;setSelectedDayRange&quot;, convertedDate);
  </code></pre>
  </li>
  </ol>
  <p>It only converts the <code>to</code> date.</p>
  <ol start="2">
  <li><p>if I try to do it like</p>
  <pre><code>     let convertedDate = moment(setSelectedDayRange).toISOString();
       console.log(&quot;setSelectedDayRange&quot;, convertedDate);
  </code></pre>
  </li>
  </ol>
  <p>It ends up converting <code>currentDate-1</code></p>
  <pre><code>handleDatePickerChange = (setSelectedDayRange) =&gt; {
          console.log(&quot;initializing handleDatePickerChange()&quot;);
          console.log(&quot;setSelectedDayRange&quot;, setSelectedDayRange);
          // TODO
          // convert the dates
          
          setSelectedDayRange = moment();
      
          let convertedDate = moment().toISOString();
          console.log(&quot;setSelectedDayRange&quot;, convertedDate);
      
      
          // let convertedDate = moment(setSelectedDayRange).toISOString();
          // console.log(&quot;setSelectedDayRange&quot;, convertedDate);
      
        
          this.setState({
            selectedDayRange: setSelectedDayRange,
          });
        };
  </code></pre>
  <p><a href="https://codesandbox.io/s/interesting-edison-h5dxm?fontsize=14&amp;hidenavigation=1&amp;theme=dark" rel="nofollow noreferrer">Sandbox URL to mess around with it.</a></p>