title: Converting HTML date from form into JavaScript to compare two dates.
body: <p>I am trying to write a program that works out the difference between two dates using JavaScript. The two dates I want to compare are entered using a HTML form using the date format. I want to compare the two entered dates using javaScript, specifically, to find the difference between the two dates in full weeks and then the remaining days. I have managed to compare two hardcoded dates in javaScript, but am having trouble doing this with two dates in a form. Any pointers would be much appreciated!
  Below is the javaScript program:</p>
  
  <pre><code>   &lt;!DOCTYPE html&gt;
     &lt;html&gt;
     &lt;title&gt; Dates &lt;/title&gt;
     &lt;head&gt;Class Test
  
     &lt;script language="javascript"&gt;
     function Ict5() { // ALERT BOX
     today = new Date(); //Using new Date(), creates a new date object with the current date and time
  
    birthday = new Date("March 28, 1995"); //using new date with stuff in the brackets, assigns the date to the variable
    birthday.setFullYear(1995); 
    msPerDay = 24 * 60 * 60 * 1000;
    msPerWeek = 7 * 24 * 60 * 60 * 1000;
    msBetween = (today.getTime() - birthday.getTime()); //get time Returns the number of milliseconds since midnight Jan 1, 1970
    daysBetween = Math.round(msBetween/msPerDay); //math round returns the value of a number rounded to the nearest integer.
    weeksBetween = Math.floor(msBetween/msPerWeek);
    window.alert("There are " +daysBetween+ " days or " +weeksBetween+ " full weeks between my date of birth and today ");
    }
    &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
  
    &lt;H1&gt; An Example of Form &lt;/H1&gt;
  
  
  
   &lt;Form action="process.pl" method="POST" name="MyForm" onsubmit="return formValidation()"&gt;
  
              &lt;p&gt;Enter Date:&lt;/p&gt;
              &lt;input type=date name="date1" id="date1"&gt;
              &lt;input type=date name="date2" id="date2"&gt;
   &lt;button type="button" onclick="Ict5()"&gt;Calculate Fare&lt;/button&gt;&lt;br&gt;
  
      &lt;/Form&gt;        
  
  
   &lt;/body&gt;
  
  &lt;/html&gt; 
  </code></pre>