I have a form that has two date fields. I am trying to select the dates from the two inputs and compare them with JQuery. The problem I am having is that it returns NaN
.
I think might be because the typeof
on the dates returns strings.
$('#id_date_completed').change(function() {
date_received = $("#id_date_received").val();
date_completed = $("#id_date_completed").val();
var diff = date_completed - date_received;
var days = diff / 1000 / 60 / 60 / 24;
console.log(days);
}
EDIT
My question differs from Get difference between 2 dates in javascript? as I am using bootstrap-datepicker library. Arun P Johny answer was perfect