0

1- I have a number of weeks from an input field:

$("#numberWeek").on("keyup", function(){
  var numberWeek =  $(this).val();
  console.log(numberWeek);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number" id="numberWeek" />

2- I have the number of the current week:

var todayDate = new Date();
var currentWeek = (0 | todayDate.getDate() / 7) + 1;
console.log(currentWeek);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

3- How can I display the date that we will find when we start to count from the current week (currentWeek) to the number of weeks that is in the variable numberWeek in this format : 26/07/2018 ?

Thanks in advance for any help.

Master Yoda
  • 4,334
  • 10
  • 43
  • 77
Diasline
  • 625
  • 3
  • 32

1 Answers1

1

You can use the moment.js (here documentation) library to achieve this easily, just use add method and pass as parameter week, something like this:

moment(todayDate).add(numberWeek, 'weeks').calendar() 

here the idea working: https://jsbin.com/rokiluxosi/1/edit?html,js,output

Jose Rojas
  • 3,490
  • 3
  • 26
  • 40