Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bhhussain's avatar

Disable the bootstrap current date after particular time.

I would like to disable the current date in the bootstrap date picker after 4 PM. If the time passed 4 PM then the user is not allowed to select the current date.

   <input class="form-control datepicker" id="datepicker2" name="wp_from_date" placeholder="dd-mm-yyyy"
              tabindex="6" value="{{ old('wp_from_date') }}" required>

            <script>
              var date = new Date();
            var today = new Date(date.getFullYear(), date.getMonth(), date.getDate());
              $('#datepicker2').datepicker({
                 format: 'dd-mm-yyyy',
                   uiLibrary: 'bootstrap4',
                   minDate: today  

               });               
            </script>

Can anyone please guide me?

The below code if for that purpose for Jquery UI datepicker but I need same for bootstrap date picker

var minDate = null;

...

if(parseInt(hour, 10) > 10) {
    minDate = 1;
}

$( ".selector" ).datepicker({
    minDate: minDate;
});

Thank you

0 likes
1 reply
bhhussain's avatar

I am using the below code and it is working fine.

           <script>
              var date = new Date();            
                           
              var hour = date.getHours();              
              if(parseInt(hour) > 15) {
                minDate = 1;                
            var today = new Date(date.getFullYear(), date.getMonth(), date.getDate());
              $('#datepicker2').datepicker({
                 format: 'dd-mm-yyyy',
                   uiLibrary: 'bootstrap4',                   
                   minDate:new Date(),
      disabledDates: [new Date()]
               });       
                }
                else
                {                  
            var today = new Date(date.getFullYear(), date.getMonth(), date.getDate());
              $('#datepicker2').datepicker({
                 format: 'dd-mm-yyyy',
                   uiLibrary: 'bootstrap4',
                   minDate: today,
                  });  
                }                        
            </script>

Please or to participate in this conversation.