• How to restrict the selectable date ranges in Bootstrap Datepicker?


    JS file:
    $(".from_date").datepicker({
        format: 'yyyy-mm-dd',
        autoclose: true,
    }).on('changeDate', function (selected) {
        var startDate = new Date(selected.date.valueOf());
        $('.to_date').datepicker('setStartDate', startDate);
    }).on('clearDate', function (selected) {
        $('.to_date').datepicker('setStartDate', null);
    });
    
    $(".to_date").datepicker({
        format: 'yyyy-mm-dd',
        autoclose: true,
    }).on('changeDate', function (selected) {
        var endDate = new Date(selected.date.valueOf());
        $('.from_date').datepicker('setEndDate', endDate);
    }).on('clearDate', function (selected) {
        $('.from_date').datepicker('setEndDate', null);
    });
    HTML:
    <input class="from_date" placeholder="Select start date" type="text" name="from_date">
    <input class="to_date" placeholder="Select end date" type="text" name="to_date">
  • 0 comments:

    Post a Comment

    FAVOURITE LINE

    To steal ideas from one is plagiarism. To steal from many is Research.

    ADDRESS

    Mumbai , Maharashtra

    EMAIL

    shikha.pathak6@gmail.com
    shikha.the.swt.pari@gmail.com

    Skype

    shikha_pari