title: Difference between two times javascript
body: <p>I have two kinds of formats  </p>
  
  <ol>
  <li><p>May 16, 12:00 PM-May 17, 12:00 AM </p></li>
  <li><p>May 16, 12:00 PM-1:00 PM. </p></li>
  </ol>
  
  <p>I want to know the number of hours between two times. I used the moment to calculate for Option 2 with the following code </p>
  
  <p>Eg: May 16, 12:00 PM-1:30 PM will return 1.5 hours</p>
  
  <pre><code>let dateTime = availablity.split(',');
  let dateTimes = availablity.split('-');
  let times = dateTime[1].split('-');
  var start = moment(times[0], 'hh:mm a');
  var end = moment(times[1], 'hh:mm a');
  var startTime = moment(start);
  var endTime = moment(end);
  var x = moment.duration(endTime.diff(startTime));
  var tempTime = moment.duration(x);
  var hours = tempTime.as('hours');     
  </code></pre>
  
  <p>How can I use the similar code to achieve number of hours for 1 format as time has for next day</p>