How to disable specific dates in datepicker

In web development, taking date input from users commonly occurs. The jQuery Date picker provides an excellent user interface and user experience. It also provides much functionality like start date, end date, format date for user display, and more.

While taking date input sometimes we need to skip some dates or need to force users not to select some specific dates like holidays. Without date picker we need to validate it against user input but date picker provides functionality to disable some dates while taking user input easily.

For example, we are creating HRMS or a school application which has a leave module. So it is normal to take leave on working days only. Users can not apply for leave on holidays or exam days. In this example, we will disable a few dates like holidays from datepicker.

<!DOCTYPE html>
    <title>Disable Specific Date In jQuery Datepicker</title>
    <link href="" rel="stylesheet" />
    <link rel="stylesheet" href="" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
    <div class="container">
        <h2>How To Disable Some Dates In jQuery Datepicker</h2>
        <div class="row mt-3">
            <div class="col-md-12 form-group">
                <label>Select Date :</label>
                <input type="text" id="datepicker" class="form-control">
    <script src=""></script>
    <script src=""></script>
    <script src="" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" crossorigin="anonymous"></script>
    <script type="text/javascript">
        $(function() {
            var holidays = ["2022-08-11","2022-08-12", "2022-08-15"]
            $( "#datepicker" ).datepicker({
                beforeShowDay: function(date){
                    var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
                    return [ holidays.indexOf(string) == -1 ]

In the above code, we have used libraries like Bootstrap, jquery-ui and jQuery and defined single input with id as datepicker. Then in the document ready method, we initialized jQuery datepicker. Here, we have created an array of holiday dates which contains three dates in august 2022. While initializing the jQuery date picker, we applied beforeShowDay property and logic to disable holiday dates defined in the holiday array.

While someone tries to select a date then it will show our holiday dates disabled and the user can not select it. Below is a simple output image for the above example.

Disable holidays in Bootstrap date picker


In this article, we have created simple date input and disabled weekends for that input. There are many options or properties which can be useful with datepicker.