Jump to content

jQuery datepicker end of month day departure +1


erme

Recommended Posts

Hi, I have 2 inputs called ArrivalDate and DepartureDate using jQuery datepicker which needs to det the departure date at least one more day from the selected arrival date. All works fine, except when we reach the end of the month insted of the departure date rolling over to the next month it just +1's the date. Eg today its showing 31 April, which dosent exsist.

$.datepicker.setDefaults({
    changeMonth: true,
    changeYear: true,
    dateFormat: 'd/m/yy',
    firstDay: 1
});

var myDate = new Date();
var prettyDate = myDate.getDate() + '/' + (myDate.getMonth()+1) + '/' + myDate.getFullYear();
var prettyDate2 = (myDate.getDate()+1) + '/' + (myDate.getMonth()+1) + '/' + myDate.getFullYear();        
    
$('#ArrivalDate').datepicker({
    minDate: new Date(),
    onSelect: function(dateStr) {
        var min = $(this).datepicker('getDate') || new Date(); // Selected date or today if none
        $('#DepartureDate').datepicker('option', {minDate: min});
    }
});
$('#DepartureDate').datepicker({
    minDate: new Date(),
    onSelect: function(dateStr) {
        var max = $(this).datepicker('getDate'); // Selected date or null if none
        $('#ArrivalDate').datepicker('option', {maxDate: max});
    }
});    

$("#ArrivalDate").val(prettyDate);
$("#DepartureDate").val(prettyDate2);

you need use getDate() to get the current day from the first date object, then add the number of days (1) to that value, then use setDate() to set the second date object to the modified value.

 

see this link - http://www.ehow.com/how_6810273_add-days-date-javascript.html

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.