How to get the time span between two date picker values in Javascript?
<p>I've added two Bootstrap Datetime pickers to a HTML5 form. So far I can capture the DateTime value of each picker using the change event of the control.</p>

<p>Now I have a case where the time span difference between both DateTime pickers needs to be stored as a var.</p>

<p>I did come across an example similar to this <a href="https://stackoverflow.com/questions/3224834/get-difference-between-2-dates-in-javascript">ask here</a>. But my short implementation below alerts a value of "Nan" instead of the expected time span difference when the actual time picker value is changed.</p>

<p><a href="https://i.stack.imgur.com/i0ZbG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i0ZbG.png" alt="enter image description here"></a></p>

<p><strong>Question:</strong></p>

<p>How can you calculate the time span between two date picker values in Javascript or JQuery?</p>

<p><strong>Code gist:</strong></p>

<pre><code>var start;
var actual;

$("#OutageStartDisplay").on("dp.change", function (e) {
    start = $('#OutageStart').val(moment(e.date).format());
});


//On change of the ActualDisplay datetime picker 
//update's the Actual hidden field with the datetime.
$("#ActualDisplay").on("dp.change", function (e) {
    actual = $('#Actual').val(moment(e.date).format());

    //If the actual is set, calculate the outage duration
    var timeDiff = Math.abs(start - actual);
    var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); 
    alert(diffDays);

});
</code></pre>