0

I'm creating a booking widget, and would like to set the "departure date" for 1 day after the arrival date. Here is what I have so far, but for some reason, it's displaying the same date instead of the next day.

jQuery(document).ready(function() {
    var nowTemp = new Date();
    var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
    var checkin = jQuery('#arrivalDate').fdatepicker({
        onRender: function (date) {
            return date.valueOf() < now.valueOf() ? 'disabled' : '';
        }
    }).on('changeDate', function (ev) {
        if (ev.date.valueOf() > checkout.date.valueOf()) {
            var newDate = new Date(ev.date);
            newDate.setDate(newDate.getDate() + 1);
            checkout.update(newDate);
        }
        checkin.hide();
        jQuery('#departureDate')[0].focus();
    }).data('datepicker');
    var checkout = jQuery('#departureDate').fdatepicker({
        onRender: function (date) {
            return date.valueOf() <= checkin.date.valueOf() ? 'disabled' : '';
        }
    }).on('changeDate', function (ev) {
        checkout.hide();
    }).data('datepicker');
});
JeremyE
  • 1,368
  • 4
  • 20
  • 40

1 Answers1

0

This question has already been answered here Incrementing a date in JavaScript but if you dont want to read it. Then you should change this

var newDate = new Date(ev.date);

to this

var newDate = new Date(ev.getDate() + 1);

Then newDate will have the current day plus one additional day that is the one that you added.

Community
  • 1
  • 1
  • I have `newDate.setDate(newDate.getDate() + 1);` right under the line you mentioned. – JeremyE Jul 08 '16 at 05:16
  • I know but newDate should be null because it was incorrectly initiliaze so when u try to `newDate.setDate(newDate.getDate() + 1);` u are saying that newdDate should be set to null plus 1. and the error is in `var newDate = new Date(ev.date);` – carlos salzar Jul 11 '16 at 03:13