Magento – Magento 2 how to restrict previous date in datepicker , for frontend detail page custom options

datedatepickermagento2product-detail-pageproduct-view-page

In Magento 2 how to restrict previous dates in datepicker ,in detail page customizable options,

Please help me out on this .

Best Answer

If you are using Magento calendar library or jQuery date picker library then use below method

require([
         "jquery",
         "mage/calendar"
         ], function ($) {

    $('#example').datepicker({
                        dateFormat: "yy-mm-dd",
                        timeFormat: "H:m:s",
                        changeMonth: true,
                        changeYear: true,
                        numberOfMonths: 1,
                        showsTime: true,
                        minDate: new Date()
                    });
});

In this, the minDate is the Date before which you want to restrict.