How to calculate the number of the week from the start and end date period?

Issue

the main idea is to get the number of the week between two dates (from a period of start date and end date)!
Something like that: if the period is 01-05-2020 to 31-05-2020 and in the data picker I chouse 08-05-2020 result will be 2, the second week.

can someone help with that can’t figure out by my self,
thank you!

here is JS date picker code line with setting up period 01-05-2020 to 31-05-2020, how to echo out from this js code number of week for future php usage or input value?

js

``````<!-- js -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js' type='text/javascript'></script>
<!-- Datepicker -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js' type='text/javascript'></script>

<script type="text/javascript">

\$('#datepicker').datepicker({
format: "dd/mm/yyyy",
startDate: new Date('2020-5-1'),
endDate: new Date('2020-5-31')
});

});
</script>
``````

html

``````<div class="form-group">
<label for="formGroupExampleInput">Date of sale</label>
<input type="text" name="dos" value="<?php echo \$doc; ?>" class="form-control" id='datepicker' id="formGroupExampleInput">
</div>
``````

Solution

Thanks, I found a solution to my problem.
Here it is, maybe someone needed..

``````<script>
function diff_weeks(dt2, dt1)
{

var diff =(dt2.getTime() - dt1.getTime()) / 1000;
diff /= (60 * 60 * 24 * 7);
return Math.abs(Math.round(diff));

}

dt1 = new Date(2014,10,2);
dt2 = new Date(2014,10,11);
console.log(diff_weeks(dt1, dt2));

dt1 = new Date("June 13, 2014 08:11:00");
dt2 = new Date("October 19, 2014 11:13:00");
console.log(diff_weeks(dt1, dt2));
<script>
``````