How to set default date in daterangepicker?

Sagar Nepali picture Sagar Nepali · Jun 27, 2017 · Viewed 19.9k times · Source

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"));

});

Answer

Dan Grossman picture Dan Grossman · Jul 20, 2017

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'
    }
});