Bootstrap datepicker disabling past dates without current date

前端 未结 20 2075
[愿得一人]
[愿得一人] 2020-11-27 04:55

I wanted to disable all past date before current date, not with current date. I am trying by bootstrap datepicker library \"bootstrap-datepicker\" and using following code:<

相关标签:
20条回答
  • 2020-11-27 05:22

    Try it :

    $(function () {
         $('#datetimepicker').datetimepicker({  minDate:new Date()});
    });
    
    0 讨论(0)
  • 2020-11-27 05:24
    <script type="text/javascript">
    $('.datepicker').datepicker({
        format: 'dd/mm/yyyy',
        todayHighlight:'TRUE',
        startDate: '-0d',
        autoclose: true,
    })
    
    0 讨论(0)
  • Disable all past date

    <script type="text/javascript">
            $(function () {
                /*--FOR DATE----*/
                var date = new Date();
                var today = new Date(date.getFullYear(), date.getMonth(), date.getDate());
    
                //Date1
                $('#ctl00_ContentPlaceHolder1_txtTranDate').datepicker({
                  format: 'dd-mm-yyyy',
                  todayHighlight:'TRUE',
                  startDate: today,
                  endDate:0,
                  autoclose: true
                });
    
            });
    </script>
    

    Disable all future date

     var date = new Date();
     var today = new Date(date.getFullYear(), date.getMonth(), date.getDate());
    
       //Date1
       $('#ctl00_ContentPlaceHolder1_txtTranDate').datepicker({
           format: 'dd-mm-yyyy',
           todayHighlight:'TRUE',
           minDate: today,
           autoclose: true
       });
    
    0 讨论(0)
  • 2020-11-27 05:24

    You can simply add data attribute in html input tag:

    In rails html :

    <%= form.text_field :appointment_date, 'data-provide': 'datepicker', 'data-date-start-date': "+0d" %>
    

    HTML :

    <input data-provide="datepicker" data-date-start-date="+0d" type="text" name="appointment_date" id="appointment_date">
    
    0 讨论(0)
  • 2020-11-27 05:24

    You can find your solution in this link below: https://codepen.io/ahmetcadirci25/pen/NpMNzJ

    Thats work for me.

    My code:

            var date = new Date();
            date.setDate(date.getDate());
    
            $('#datetimepicker1').datetimepicker({
                isRTL: false,
                format: 'dd.mm.yyyy hh:ii',
                autoclose: true,
                language: 'tr',
                startDate: date
            });
    
    0 讨论(0)
  • 2020-11-27 05:25

    Here it is

     <script>
              $(function () {
                  var date = new Date();
                  date.setDate(date.getDate() - 7);
    
                $('#datetimepicker1').datetimepicker({
                    maxDate: 'now',
                    showTodayButton: true,
                    showClear: true,
                    minDate: date
                });
            });
        </script>
    
    0 讨论(0)
提交回复
热议问题