0

Need answer as soon as possible!

How to get a end date based on a inputted day interval and start date like if i have a start date that has a value of 4/19/2015 and the then the inputted day interval is like 10 how would I do that in jquery and the event will trigger if the value inside the datepicker input box changed.

Guys I will appreciate all your help T_T.

2 Answers2

1

you may refer to the answer How to add number of days to today's date?

Assuming, you are using jqueryui datepicker. if so, use following code to get the selected date, as soon as the date is selected from the datepicker.

<script>
  $(function() {
    $( "#from" ).datepicker({
      onSelect: function( selectedDate ) {
        var startDate = selectedDate; // you got the startDate here
      }
    });
  });
 </script>
Community
  • 1
  • 1
Jacob Nelson
  • 2,370
  • 23
  • 35
0

please find the solution below:

HTML:

<input type="text" id="start-date-picker" />
<input type="text" id="end-date-picker" />

JS:

$('#start-date-picker').datepicker();
$('#end-date-picker').datepicker();


$('#start-date-picker').change(function(){
    var interval = 10;

  function convertDateString(p) { return (p < 10) ? '0' + p : p; }

  var startDate = new Date($(this).val());
  startDate.setDate(startDate.getDate() + interval);
    $('#end-date-picker').val(convertDateString(startDate.getMonth() + 1) + '/' + convertDateString(startDate.getDate()) + '/' + startDate.getFullYear());
});

JS Fiddle Demo

kbysiec
  • 578
  • 1
  • 4
  • 21