title: How to calculate the hours between two times with jquery?
body: <p>I am trying to calculate the hours between two times.</p>
  
  <p>Below is where I am currently but this code fails in two ways.</p>
  
  <p><strong>1).</strong> I need <code>.Hours</code> to output time in decimal. </p>
  
  <p><em>(e.g one and half hours should output 1.5 and 15mins should be 0.25).</em></p>
  
  <p><strong>2).</strong> Calculation currently does not treat values for time as <code>time</code>.</p>
  
  <p><em>(e.g 23:00 to 2:00 should equal <code>3</code> and <strong>NOT</strong> <code>-21</code> as currently).</em></p>
  
  <hr>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;input class="Time1" value="10:00" /&gt;
  &lt;input class="Time2" value="12:00" /&gt;
  &lt;input class="Hours" value="0" /&gt;
  </code></pre>
  
  <p><strong>JQUERY</strong></p>
  
  <pre><code> $(function () {
       function calculate() {
           var hours = parseInt($(".Time2").val().split(':')[0], 10) - parseInt($(".Time1").val().split(':')[0], 10);
           $(".Hours").val(hours);
       }
       $(".Time1,.Time2").change(calculate);
       calculate();
   });
  </code></pre>
  
  <p><a href="http://jsfiddle.net/44NCk/" rel="noreferrer">http://jsfiddle.net/44NCk/</a></p>