JSFiddle - React, Tailwind, and code Playground

by Rodmunera

HTML

<button>test</button>
<div></div>

JavaScript

var _MS_PER_DAY = 1000 * 60 * 60 * 24;

// a and b are javascript Date objects
dateDiffInDays = function(a, b) {
  // Discard the time and time-zone information.
  var utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
  var utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());

  return Math.floor((utc2 - utc1) / _MS_PER_DAY);
}
    validDateGapOrOverlap = function(endDate,startDate,gapDaysAllowed){
		//enddate belongs to the previous slab than the startDate
        var jsEndDate = new Date(endDate);
        var jsStartDate = new Date(startDate);
        var diffInDays=dateDiffInDays(jsEndDate,jsStartDate);
        //returns true if there's a gap or an overlap
        return diffInDays===gapDaysAllowed;
	}

$(document).on('click','button',function(){
    var result=validDateGapOrOverlap('12/9/2014','12/10/2014',1);
    console.log(result);
    $('div').html(result);
});