We help IT Professionals succeed at work.

Setting the minDate and maxDate from the current date, using jQuery Date Picker

curiouswebster
on
I need the value of the year to go back in time no more than 75 years, I assume I'd need to explicitly set the minDate to this year - 75.

Is that right? Where do I set that value?

Thanks!
Comment
Watch Question

$( "#myElementId" ).datepicker({ minDate: '-75Y'});

Open in new window


"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."

From the docs.
curiouswebsterSoftware Engineer

Author

Commented:
Great. I presume your '#myElementId' is the same as my '#datepicker'?

How does this:
.datepicker({ minDate: '-75Y'});

 relate to the other coded needed to instantiate my control?

    $(function () {
        $("#datepicker").datepicker({
            changeMonth: true,
            changeYear: true
        });
    });
$(function () {
        $("#datepicker").datepicker({
            changeMonth: true,
            changeYear: true,
            minDate: '-75Y'
        });
    });

Open in new window


It's just another option.
curiouswebsterSoftware Engineer

Author

Commented:
Thanks!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.