Skip to main content
6 de 6
Melhoria das palavras utilizadas na resposta
user avatar
user avatar

Provavelmente seu problema é na formatação da data.

Por favor, veja se esse código resolve:

HTML:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css"/>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/momentjs/2.10.6/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/bootstrap.datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"> </script> 

<div class="input-group" id="DateDemo">
     <input type='text' id='weeklyDatePicker' placeholder="Selecione a Semana" />
</div>

JavaScript:

 $(document).ready(function(){
 
 $("#weeklyDatePicker").datetimepicker({
     format: 'DD-MM-YYYY'
 });
  
 $('#weeklyDatePicker').on('dp.change', function (e) {
     var value = $("#weeklyDatePicker").val();
     var firstDate = moment(value, "DD-MM-YYYY").day(0).format("DD-MM-YYYY");
     var lastDate =  moment(value, "DD-MM-YYYY").day(6).format("DD-MM-YYYY");
     $("#weeklyDatePicker").val(firstDate + " - " + lastDate);
 });
});

Segue exemplo funcionando JSFiddle

user167899