How to set default date in daterangepicker?

混江龙づ霸主 提交于 2020-05-29 03:49:11

问题


Is there any way to simply set default date as current + 5 day ahead in daterangepicker? Like this:

$('.selector').daterangepicker({
singleDatePicker: true,
showDropdowns: true,
setDate: '+5d',
minDate: new Date()
}, function(start, end, label) {
    $('.selector').val(start.format("YYYY-MM-DD"));

});

回答1:


Like so. You also don't need that callback function since the format string is configurable.

$('.selector').daterangepicker({
    singleDatePicker: true,
    showDropdowns: true,
    startDate: moment().add(5, 'day'),
    minDate: moment(),
    locale: { 
        format: 'YYYY-MM-DD'
    }
});



回答2:


var someDate = new Date(); var numberOfDaysToAdd = 5; someDate.setDate(someDate.getDate() + numberOfDaysToAdd); $('.selector').val(formatDate(someDate));

this helped




回答3:


Try this:

$('.selector').daterangepicker({
singleDatePicker: true,
showDropdowns: true,
minDate: new Date()
}, function(start, end, label) { $('.selector').val(start.format("YYYY-MM-DD"));

});

var Today= new Date();
Today.setDate(Today.getDate() + 5);//any date you want
$('.selector').daterangepicker('setDate', Today);


来源:https://stackoverflow.com/questions/44776463/how-to-set-default-date-in-daterangepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!