Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Objective:

To calculate the duration

Problem

Calculate duration in between 2 given dates.

Screenshot:

Code:

Code Block
langjavascript
$('input[name="fromDatepicker"], input[name="toDatepicker"]').change( function(){
      d1 = $('input[name="fromDatepicker"]').datepicker('getDate');
      d2 = $('input[name="toDatepicker"]').datepicker('getDate');
      diff = 0;
      if (d1 && d2) {
            diff = Math.floor((d2.getTime() - d1.getTime()) / 86400000); // ms per day
      }
      $('input[name=days]').val(diff);
});

Sample App Download

View file
nameAPP_calculateDateDiff-1-20160404092232.zip
height250