Reputation: 4997
Is it possible to specify the date during initialization using the Eternicode Bootstrap Datepicker? By default, when initializing the picker, the current date will be selected. I want a different date (in the future) to be selected. Is this possible and how so?
Here is my initialization code:
datePicker = detePickerElem.datepicker({
format: 'mm/dd/yyyy',
maxViewMode: 'months',
startDate: new Date(),
todayBtn: true,
todayHighlight: true,
weekStart: 1
});
datePicker.datepicker('setDate', new Date(futureDateObject));
I've tried using the setDate
method to set the date after initialization, but this doesn't do anything. Note that for various reasons I'm using an older release (v1.3) of the project and am not able to migrate to a newer release, however I can fork the repo and modify the source if needed.
Upvotes: 1
Views: 21927
Reputation: 13161
If you want date selection greater than today, you should set start date tomorrow. Also no need for todayBtn when it isn't selectable.
var tomorrow = new Date();
tomorrow.setDate(new Date().getDate()+1);
datePicker = detePickerElem.datepicker({
format: 'mm/dd/yyyy',
maxViewMode: 'months',
startDate: tomorrow,
todayBtn: false,
todayHighlight: true,
weekStart: 1
});
datePicker.datepicker('setDate', tomorrow);
Upvotes: 1
Reputation: 88
Since you mentioned you are using eternicode Bootstrap datepicker, if you look at the options on https://github.com/eternicode/bootstrap-datepicker/blob/ca11c450/README.md#options there is a way to set a custom startdate as below:
$('#datepicker').datepicker('setStartDate', '2015-01-01');
Another thread that might be of help here its shown how to increment by 1 day: Bootstrap DatePicker, how to set the start date for tomorrow?
Upvotes: 3