Bootstrap Date Range Picker -> Single Date Picker: How to set a Date

Navas Basheer picture Navas Basheer · Apr 22, 2017 · Viewed 9.9k times · Source

I'm experimenting with Boootstrap Date Range Picker

Whats the best way to set Date into a Single Date Picker via Javascript?

Single Date Picker initialization code

$(#date).daterangepicker({
    locale: {
          format: 'DD/MM/YYYY',
    },
    singleDatePicker: true,
    showDropdowns: true
});

I tried with below code:

$("date").data('daterangepicker').setStartDate(data.startDate);

This way, I'm getting below output, which is not really acceptable!!! enter image description here

Hope someone come up with a nice solution.

Cheers!!

Answer

Roy Chan picture Roy Chan · Sep 26, 2017

Try

$("date").data('daterangepicker').setStartDate(data.startDate);
$("date").data('daterangepicker').setEndDate(data.startDate);

That is the only way I can find so far.