jQuery UI & Datepicker: Restrict date range

This entry is part 6 of 14 in the series jQuery UI Datepicker

jQuery UI Datepicker – Restrict date range

Restrict the range of selectable dates with the minDate and maxDate options.

Set the beginning and end dates as actual dates (new Date(2009, 1 – 1, 26)), as a numeric offset from today (-20), or as a string of periods and units (‘+1M +10D’).

For the last, use ‘D’ for days, ‘W’ for weeks, ‘M’ for months, or ‘Y’ for years.

<!doctype html>
<html lang='en'>
    <meta charset='utf-8'>
    <title>jQuery UI Datepicker - Restrict date range</title>
    <link rel='stylesheet' href='//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css'>
    <script src='//code.jquery.com/jquery-1.10.2.js'></script>
    <script src='//code.jquery.com/ui/1.10.4/jquery-ui.js'></script>
    <link rel='stylesheet' href='http://codecrawl.com/code/jqueryui/jqueryui_style.css'>
        $(function () {
            $('#datepicker').datepicker({ minDate: -20, maxDate: '+1M +10D' });

<p>Date: <input type='text' id='datepicker'></p>

Try The Code Datepicker Widgets API Doc
Series Navigation<< jQuery UI & Datepicker: Dates in other months
jQuery UI & Datepicker: Display button bar >>

Leave a comment

Leave a Reply