JSFiddle - React, Tailwind, and code Playground

HTML

<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<div id="datepicker-start"></div>
<div id="datepicker-end"></div>

<a class="foo" href="#">calculate weeks</a>

JavaScript

$("#datepicker-start").datepicker();
$("#datepicker-end").datepicker();

var getWeeklyEventCount = function (startDate, endDate) {
    var secondOccurrence = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate()+7);
    if (endDate.getTime() >= secondOccurrence.getTime()) {
        return 1 + getWeeklyEventCount(secondOccurrence, endDate);
    }
    if (endDate.getTime() >= startDate.getTime()) {
        return 1;
    }
    return 0;
};

$("a.foo").click(function(){
    var count = getWeeklyEventCount($("#datepicker-start").datepicker("getDate"), $("#datepicker-end").datepicker("getDate"));
    alert(count);
});