user405398
user405398

Reputation:

How do I set start year and end year of jquery date picker?

When I initialize a jquery date picker like

$( "#datepicker" ).datepicker({
    changeMonth: true,
    changeYear: true
});

The showing the date picker from year 2000 to year 2020.

EDIT:

When i go to year 2000, the next time it shows from 1990, but any way I want to customize it.

How do I set the from year and to year that will fit for my requirements.

Thanks in advance.

Upvotes: 7

Views: 36621

Answers (6)

Jasim Juwel
Jasim Juwel

Reputation: 766

start date must be limit at most 2 year selection

 $(document).on('change', '#startdate', function () {
        var current=$(this).val();
        var currentYear = current.split("-");
        var compareYear=(new Date().getFullYear()-1);
            if(compareYear > currentYear[0]){
                $('#limitMsg').text('this year must at most one year from current date');
                $('#submit').prop('disabled', true);
            }else{
                $('#limitMsg').text('');
                $('#submit').prop('disabled', false);
            }
  });

Upvotes: 0

Fabian Marz
Fabian Marz

Reputation: 219

You could also do something like following:

'yearRange': '1945:' - End year is the current one.

'yearRange': '1945:+10 - Add +10 years to the current one.

'yearRange': '1945:-10 - Subtract -10 years from the current one.

Upvotes: 1

Ramkumar P
Ramkumar P

Reputation: 206

Try with this:

$('#license_expiry_date').datepicker({changeMonth: true, 
                                      changeYear: true, 
                                      yearRange: '-100:+100',
                                      maxDate: new Date(2100, 1,18) });

Upvotes: 3

Ansyori
Ansyori

Reputation: 2835

$(function() {
    $( "#datepicker" ).datepicker({
      changeMonth: true,
      changeYear: true,
      yearRange: '1945:'+(new Date).getFullYear()         
    });
});

this example for year start from 1945 to current year

Upvotes: 13

Ariful Islam
Ariful Islam

Reputation: 7675

$( "#datepicker" ).datepicker({
        changeMonth: true,
        changeYear: true,
        yearRange: '1972:2011'
    });

Should be work well.

Upvotes: 8

Pekka
Pekka

Reputation: 449475

See the documentation: The option is called yearRange.

Control the range of years displayed in the year drop-down: either relative to today's year (-nn:+nn), relative to the currently selected year (c-nn:c+nn), absolute (nnnn:nnnn), or combinations of these formats (nnnn:-nn). Note that this option only affects what appears in the drop-down, to restrict which dates may be selected use the minDate and/or maxDate options.

Upvotes: 7

Related Questions