Recently, I am working on a project that should implement some pages using datepicker for more convenient use by users, more specific Bootstrap 3 DatePicker, in particular, I believe that this is the best structure I've ever met on the Internet. While I was developing, I found the same problem that you are describing, but as I do not know what specific structure you are using, I am describing my solution and my code. The structure under consideration was Bootstrap 3 Datepicker . This answer may not be suitable for some users using frameworks other than this.
My HTML is:
<div class="form-group form-group-md" align="left"> <label for="inputDataInicial" class="col-form-label">Data Inicial:</label> <div class="inputDataInicial" name="inputDataInicial" id="inputDataInicial"></div> </div>

To initialize datepicker:
$("#inputDataInicial").datetimepicker({ format: 'DD/MM/YYYY', locale: 'pt-br', useCurrent: true, inline: true, sideBySide: true }).on('dp.change', function(e){ $('.inputDataInicial').val(e.date.format('YYYYMMDD')); });
Then I set the default date using moment framework - Bootstrap 3 Datepicker uses it:
var currentDate = moment().format('YYYYMMDD'); $('.inputDataInicial').val(currentDate); $('.inputDataFinal').val(currentDate);
Finally, I selected a simple button to get the selected date:
$(".btn_relatorio_amap_gerar").unbind("click").on("click",function(e) { var data_inicial = $(".inputDataInicial").val() + ' 00:00:00'; var data_final = $(".inputDataFinal").val() + ' 23:59:59'; alert(data_inicial + ' - ' + data_final); });
Result:

I hope this helps you.
Ellington brambila
source share