Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

292
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda