Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

421
Views
How to enable year Before/After Specific year in Datepicker

I am showing only year in calender view using datepicker.

But I want to set maximum year range to current year and minimum year range to 1900 and disable year before/after range I want to set in Datepicker like the below image.

enter image description here enter image description here

Here is my javascript code:

$("#datepicker").datepicker({
        format: "yyyy",
        viewMode: "years",
        minViewMode: "years",
        autoclose: true,
        changeYear: true,
        yearRange: '1900:' + new Date().getFullYear()
    });

But year range is not working for me. Any help will be highly appreciated.

Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

edit - different approach


try using the minDate and maxDate attributes:

let cur_year = (new Date).getFullYear();
$( "#datepicker" ).datepicker({
    minDate: new Date(1900, 0, 1),
    maxDate: new Date(cur_year, 11, 31)
});

you should convert the date back to string after you get the current year, currently, you are trying to add a date to a string (that's not possible)

so it should look something like that:

$("#datepicker").datepicker({
        format: "yyyy",
        viewMode: "years",
        minViewMode: "years",
        autoclose: true,
        changeYear: true,
        yearRange: '1900:' + new Date().getFullYear().toString()
    });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!