Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery datepicker date +1 is adding 10 days

Tags:

jquery

I have following code

$("#in").datepicker({
    minDate: 0,
    onSelect: function (dateText, inst) {
        dateText = new Date(dateText);
        dateText = dateText.getDate()+1;
        $('#out').datepicker("option", 'minDate', dateText);
    }
});

Example: https://jsfiddle.net/ANYTA/1/

However, the out datepicker is adding 10 days instead of 1 day. What could be modified to make it work as intended? thank you very much

like image 558
cicakman Avatar asked Feb 19 '26 00:02

cicakman


1 Answers

dateText = dateText.setDate(dateText.getDate()+1);

NOTE

somedate.setDate(days);
  1. days is integer

  2. Expected values are 1-31, but other values are allowed:

      2.1) 0 will result in the last hour of the previous month

       2.1) -1 will result in the hour before the last hour of the previous month

  1. when month has 31 days, then 32 will result in the first day of the next month

  2. If month has 30 days then, 32 will result in the second day of the next month


Your code shoule

$("#in").datepicker({
    minDate: 0,
    onSelect: function(dateText, inst) {
       var actualDate = new Date(dateText);
       var newDate = new Date(actualDate.getFullYear(), actualDate.getMonth(), actualDate.getDate()+1);
        $('#out').datepicker('option', 'minDate', newDate );
    }
});

$("#out").datepicker();

DEMO

like image 54
thecodeparadox Avatar answered Feb 21 '26 13:02

thecodeparadox