Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

423
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda