erme Posted April 30, 2014 Share Posted April 30, 2014 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); Quote Link to comment https://forums.phpfreaks.com/topic/288131-jquery-datepicker-end-of-month-day-departure-1/ Share on other sites More sharing options...
mac_gyver Posted April 30, 2014 Share Posted April 30, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/288131-jquery-datepicker-end-of-month-day-departure-1/#findComment-1477700 Share on other sites More sharing options...
erme Posted April 30, 2014 Author Share Posted April 30, 2014 I set up this var prettyDate2 = (myDate.getDate()+1) + '/' + (myDate.getMonth()+1) + '/' + myDate.getFullYear(); $("#DepartureDate").val(prettyDate2); How would I adapt it to use set date? Quote Link to comment https://forums.phpfreaks.com/topic/288131-jquery-datepicker-end-of-month-day-departure-1/#findComment-1477708 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.