Nicholas Nicholas - 14 days ago 5
PHP Question

Resctrict date in datepicker

I have some datepicker which use in check in and check out date. I want to restrict check in date just until 31 December every year and cannot display 1 january in next year. And in the check out date it just display 1 january in next year. Example, I can check in on 31 December 2016 but I just can check out in 1 january 2017, cannot in 2 January 2017.

Thank you.

Answer

You can use maxDate of the datepicker UI.

For check-in:

$(document).ready(function () {
    var today = new Date();
    var lastDate = new Date(today.getFullYear(), 11, 31);
    $('#check-in').datepicker({
        maxDate: lastDate
    });
});

This will limit up to December 31 of current year.

For check-out:

$(document).ready(function () {
    var today = new Date();
    var lastDate = new Date(today.getFullYear(), 11, 32);
    $('#check-out').datepicker({
        maxDate: lastDate
    });
});

This will limit up to January 1 of next year.

Comments