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

290
Vistas
Datetime-local limit past and future date JavaScript

I have 2 inputs for datetime-local (start-time & end-time). I want to limit the start date to select only the last 72 hours which I did but i cannot restrict future time. I only want today and only last 3 days. And for end time only today and next 3 days. This is my code:

<input type="datetime-local" name="start_timestamp" id="start_timestamp" required>
            
<input type="datetime-local" name="end_timestamp" id="end_timestamp" required>

<script>
    //Do not let to select START TIME  in the PAST
    var today = new Date();
    var past = new Date(today.setDate(today.getDate() - 3)).toISOString().slice(0, 16);
    

    document.getElementsByName("start_timestamp")[0].min = past;
    document.getElementsByName("start_timestamp")[0].max = today;
</script>


            
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

See here a possible fix.

<input type="datetime-local" name="start_timestamp" id="start_timestamp" required>
            
<input type="datetime-local" name="end_timestamp" id="end_timestamp" required>




<script>
    //Do not let to select START TIME  in the PAST
    let today = new Date();
    let past = new Date(today.setDate(today.getDate() - 3)).toISOString().slice(0, 16);
    today = new Date().toISOString().slice(0, 16);

    document.getElementsByName("start_timestamp")[0].min = past;
    document.getElementsByName("start_timestamp")[0].max = today;
    
    document.getElementsByName("end_timestamp")[0].min = past;
    document.getElementsByName("end_timestamp")[0].max = today;
    
</script>

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