Reputation:
I am using the following code to Get the maxDate
from datepicker but i doesnt seem to work. Can you spot any errors in the code.
$('#date_tim').appendDtpicker({
futureOnly:true,
autodateOnStart:false,
minTime:"10:00",
maxTime:"18:00",
maxDate : '+3M',
minDate: 0,
closeOnSelected: true
});
Thanks
Upvotes: 6
Views: 169
Reputation: 2708
Try this
$(function(){
myDate = new Date();
myDate .setMonth(myDate.getMonth()+3);
$('#date_tim').appendDtpicker({
futureOnly:true,
autodateOnStart:false,
minTime:"10:00",
maxTime:"18:00",
maxDate : myDate,
closeOnSelected: true
});
});
Here is working fiddle http://jsfiddle.net/gqvxs0wg/1/
Not : maxDate option have a bug in version v1.13.0. Although it working fine with version v1.12.0. In version v1.13.0 it will show error on last month of your date range.
To fix that you need to change this line
newdate = $picker.data("maxDate");
to
newdate = new Date($picker.data("maxDate"));
at line no 408 in file jquery.simple-dtpicker.js
Upvotes: 1
Reputation: 340
For setting the date range:
$('#date_tim').appendDtpicker({
maxDate : '2016/11/10',
minDate: '2016/09/10'
});
For setting a date you can use the below code:
$('#date_tim').handleDtpicker('setDate', new Date(2016, 09, 10, 0, 0, 0));
You need to mention whatever date and time you want to set inside the new Date();
Upvotes: 1
Reputation: 1837
You use maxDate and minDate format for jQuery UI Datepicker. But you use another jQuery plugin (jquery.simple-dtpicker.js). You should set date objects to this options, see example below:
$('#date_tim').appendDtpicker({
futureOnly: true,
autodateOnStart: false,
minTime: "10:00",
maxTime: "18:00",
minDate: new Date(),
maxDate: calculateMaxDate(3),
closeOnSelected: true
});
function calculateMaxDate(monthsCount) {
var date = new Date();
date.setMonth(date.getMonth() + monthsCount);
return date;
}
Upvotes: 0