Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.