0

I would like to display the difference between two dates:

 date_debut<input type="text"name="date_debut" id="datepicker">
</br>

date fin<input type="text"name="date_fin"id="datepicker2">
</br>

nombre jour <input type="text"name="nombre_jour">
</br>

I want to enter the date start and end date and affect me in the number of days - the difference of two dates.

I made a small script, but it does not work. I'm a beginner to JavaScript and I had no time to learn JavaScript.

Here is the script I have made:

$('#datepicker, #datepicker2').datepicker();

$('button').click(function () {
    var start = $('#datepicker').val(),
        end = $('#datepicker2').val();

    var diffInDays = moment(end).diff(moment(start), 'days');

    alert(diffInDays);
});
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Igoussam
  • 3
  • 3

1 Answers1

0

According to Comparing Datepicker Dates Javascript, use .datepicker("getDate") instead of .val() to get the date and then it should just be:

var days = (end - start) / (86400 * 1000)
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kristianmitk
  • 4,528
  • 5
  • 26
  • 46