title: How to validate date ranges with HTML5 date inputs?
body: <p>The function <code>TwoFunctions()</code> is called when the 'Find Flights' button in the HTML is clicked. It will then call the two remaining functions. </p>
  
  <p>The first one, <code>Format()</code>, is used to check whether the format entered is correct and if the a date has been entered at all. This function seems to work fine and validates/invalidates correctly. </p>
  
  <p>But the second one, <code>validDate()</code> doesn't seem to invalidate dates three months in the future or an arrival time being before a departure time and was wondering why?</p>
  
  <p>I have used alerts to check that the function is being called but it is still stating that 'Dates are validated' when they should not be.</p>
  
  <pre><code>var departuredate = document.getElementById("departdate").value; 
  var arrivaldate = document.getElementById("arrivedate").value;
  
  var months3 = 90 * 24 * 60 * 60 * 1000; //3 months 
  var departuserspecifiedTime = departuredate.getTime();
  var arrivaluserspecifiedTime = arrivaldate.getTime();  
  var currentTime = CurrentDate.getTime(); //current time and date
  var departdifference = departuserspecifiedTime - currentTime; //difference between departure time and the current time
  var arrivaldifference = arrivaluserspecifiedTime - currentTime; //difference between arrival time and the current time
  
  function TwoFunctions() {
      departuredate = document.getElementById("departdate").value;
      arrivaldate = document.getElementById("arrivedate").value;
      //alert(departuredate);
      //alert(arrivaldate);
  
      var result = Format();
      var result1 = validDate();
  
      if (result == true) {
          result1;
      } else {
          alert("Error 123");
      }
      return result
  }
  
  function validDate() {
      alert('debug');
      if (departdifference &lt;= (1000 * 60 * 60)) //if the departure time is in the past or within an hour of the current time, it is invalidated as it is too soon
      {
          document.getElementById("temp").innerHTML = "Date selected is in the past";
          document.MyForm.departdate.focus();
          document.getElementById("departdate").style.border = '1px solid red';
          return false;
      } else if (arrivaldifference &lt;= (1000 * 60 * 60)) //if the arrival time is in the past or within an hour of the current time, it is invalidated as it is too soon
      {
          document.getElementById("temp").innerHTML = "Date selected is in the past";
          document.MyForm.arrivedate.focus();
          document.getElementById("arrivedate").style.border = '1px solid red';
          return false;
      } else if (departdifference &amp;&amp; arrivaldifference &gt;= months3) //if the departure/arrival date is over 3 months away from todays date it is invalidated
      {
          document.getElementById("temp").innerHTML = "Only 3 months          advance booking is allowed";
          document.getElementById("departdate").style.border = '1px solid red';
          document.getElementById("arrivedate").style.border = '1px solid red';
          return false;
      } else if (arrivaluserspecifiedTime &lt; departuserspecifiedTime) // if the arrival date is before the departure date it is invalidated 
      {
          alert("Arrival date selected is before the departure date");
          document.getElementById("departdate").focus();
          document.getElementById("arrivedate").focus();
          document.getElementById("departdate").style.border = '1px solid red';
          document.getElementById("arrivedate").style.border = '1px solid red';
          return false;
      } else {
          alert('Dates are validated');
          return true;
      }
  }
  </code></pre>
  
  <p>Basically I am wondering why the function above is invalidating all entries and not invalidating them as I had hoped the code would.</p>