title: Calculate duration between two date times in javascript
body: <p>I need to calculate the duration between two datetimes in JavaScript. I have tried this code:</p>
  
  <pre><code>var today = new Date();
  var dd = today.getDate();
  var mm = today.getMonth()+1; //January is 0!
  
  var yyyy = today.getFullYear();
  if(dd&lt;10){dd='0'+dd} if(mm&lt;10){mm='0'+mm} today = mm+'/'+dd+'/'+yyyy;  //Current Date
  console.log("current date"+today);
  
  
  var valuestart ="8:00 AM";
  var valuestop = "4:00 PM";//$("select[name='timestop']").val();
  
  //create date format          
  var timeStart = new Date("01/01/2007 " + valuestart).getHours();
  var timeEnd = new Date("01/01/2007 " + valuestop).getHours();
  
  var hourDiff = timeEnd - timeStart;             
  console.log("duration"+hourDiff);
  </code></pre>
  
  <p>From this, I am able to get Current Date and duration. But when I replace the date "01/01/2007" with the variable "today", I am getting the result as NaN. Please guide me in where I am wrong. Thanks in advance.</p>