Bootstrap datepicker: Select entire week and put week interval in input field

后端 未结 6 1712
借酒劲吻你
借酒劲吻你 2020-12-23 17:50

I am currently using bootstrap-datepicker (https://github.com/eternicode/bootstrap-datepicker), but want to be able to select entire weeks in the calendar (Monday to Sunday)

6条回答
  •  情话喂你
    2020-12-23 18:41

    I have optimized the above mentioned examples.

    HTML

    JS

    $(document).ready(function(){
        moment.locale('en', {
          week: { dow: 1 } // Monday is the first day of the week
        });
    
      //Initialize the datePicker(I have taken format as mm-dd-yyyy, you can     //have your owh)
      $("#weeklyDatePicker").datetimepicker({
          format: 'MM-DD-YYYY'
      });
    
       //Get the value of Start and End of Week
      $('#weeklyDatePicker').on('dp.change', function (e) {
          var value = $("#weeklyDatePicker").val();
          var firstDate = moment(value, "MM-DD-YYYY").day(0).format("MM-DD-YYYY");
          var lastDate =  moment(value, "MM-DD-YYYY").day(6).format("MM-DD-YYYY");
          $("#weeklyDatePicker").val(firstDate + " - " + lastDate);
      });
    });
    

    CSS

    .bootstrap-datetimepicker-widget .datepicker-days table tbody tr:hover {
        background-color: #eee;
    }
    

    Check the link for demo: https://jsfiddle.net/IamMHussain/ozdrdbqf/1/

提交回复
热议问题